Noskiw Posted April 18, 2010 Share Posted April 18, 2010 <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 Quote Link to comment https://forums.phpfreaks.com/topic/198954-error-checking-user/ Share on other sites More sharing options...
F1Fan Posted April 18, 2010 Share Posted April 18, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044355 Share on other sites More sharing options...
Noskiw Posted April 19, 2010 Author Share Posted April 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044644 Share on other sites More sharing options...
F1Fan Posted April 19, 2010 Share Posted April 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044650 Share on other sites More sharing options...
Noskiw Posted April 19, 2010 Author Share Posted April 19, 2010 That's exactly what i'm looking for. Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/198954-error-checking-user/#findComment-1044655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.