Jump to content

Recommended Posts

<script type="text/javascript">

var password = "bambam";

function prtyo(){
    prompt("Enter password");
    
    if(prompt != password){
        alert("Wrong password, please try again ");
        prompt("Enter password");
    }else{
        window.location = "ohai.php";  
    }
}

prtyo();

</script>

 

What's going on here is that I would like the user to enter  a "password" to be redirected to a different page. But yet, It only checks it twice, even if it is wrong, it will still allow them to see the page, but won't redirect it.

 

Any help will be appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/198954-error-checking-user/
Share on other sites

First, you aren't assigning prompt a value. Second, you should just call the function again, rather than prompting again. Something like this:

<script type="text/javascript">

var password = "bambam";

function prtyo(){
    var p = prompt("Enter password");
   
    if(p != password){
        alert("Wrong password, please try again ");
        prtyo();
    }else{
        window.location = "ohai.php"; 
    }
}

prtyo();
</script>

 

Also, do you realize that anyone can just view the source of the page and see what the password is?

Link to comment
https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044355
Share on other sites

Thankyou for that, But now I have another problem.... If the user wishes to cancel, he/she can't leave the webpage. I have already setup the variable defining the confirm function, but I wouldn't know where to go from there. Any tips/pointers?

 

<script type="text/javascript">

var password = "bambam";

function prtyo(){
    var p = prompt("Enter password");
    var cancel = confirm("Are you sure you want to leave this webpage?");
   
    if(p != password){
        alert("Wrong password, please try again ");
        prtyo();
    }else{
        window.location = "ohai.php"; 
    }
}

prtyo();
</script>

Link to comment
https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044644
Share on other sites

Is this what you're looking for?

 

<script type="text/javascript">

var password = "bambam";

function prtyo(){
    var p = prompt("Enter password");
   
    if(p != password){
        var cancel = confirm("Wrong password, do you want to try again?");
        if (cancel){
            prtyo();
        }
    }else{
        window.location = "ohai.php"; 
    }
}

prtyo();
</script>

Link to comment
https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044650
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.