izildop Posted January 6, 2016 Share Posted January 6, 2016 Hello I'm beginner with php, but I have a good question. I have a html page with a navigationbar, let's say I click on my navbar about me, just for example. How can I lock the screen with a password before someone can start clicking or scrolling in the about me page. So only the one with the password can enter that single page that is locked. Doing this with javascript is not good because you can open the web codes and see what the password is. How do I do this in PHP, anyone can help? Quote Link to comment https://forums.phpfreaks.com/topic/300201-php-page-lock-put-password-to-enter-page/ Share on other sites More sharing options...
requinix Posted January 6, 2016 Share Posted January 6, 2016 Pretty simple: use a form to post a password to the page, then only show the page if the right password was sent. Basically, <!-- header of your page, up until the content area --> <?php if (!isset($_POST["password"]) || $_POST["password"] != "yourpasswordhere") { // no password or wrong password ?> <form action="" method="post"> <p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p> </form> <?php } else { // correct password ?> <!-- normal page content --> <?php } ?> <!-- footer of your page -->Every time they visit the page they have to enter the password. It won't "remember" them. Quote Link to comment https://forums.phpfreaks.com/topic/300201-php-page-lock-put-password-to-enter-page/#findComment-1529201 Share on other sites More sharing options...
izildop Posted January 7, 2016 Author Share Posted January 7, 2016 Pretty simple: use a form to post a password to the page, then only show the page if the right password was sent. Basically, <!-- header of your page, up until the content area --> <?php if (!isset($_POST["password"]) || $_POST["password"] != "yourpasswordhere") { // no password or wrong password ?> <form action="" method="post"> <p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p> </form> <?php } else { // correct password ?> <!-- normal page content --> <?php } ?> <!-- footer of your page -->Every time they visit the page they have to enter the password. It won't "remember" them. <!doctype html> <html> <head> <title> Basisschool De Regenboog </title> <style> img { position: absolute; left: 60%; } </style> </head> <body> <a href="http:/www.youtube.com"><img src="Plaatjes/youtube.png" /> <script> </script> <!-- header of your page, up until the content area --> <?php if (!isset($_POST["password"]) || $_POST["password"] != "123") { // no password or wrong password ?> <form action="" method="post"> <p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p> </form> <?php } else { // correct password ?> <!-- normal page content --> <?php } ?> <!-- footer of your page --> </body> </html> I put a youtube button link on the page, but when I click to write down the password it directly send me to youtube, and it shouldn't show the button or atleast only unlock the page when you put the pass in. Mabey I misunderstood something (just a beginner) Quote Link to comment https://forums.phpfreaks.com/topic/300201-php-page-lock-put-password-to-enter-page/#findComment-1529237 Share on other sites More sharing options...
Ch0cu3r Posted January 11, 2016 Share Posted January 11, 2016 The contents of the page your want to "password protect" need to go where this line is <!-- normal page content -->, Example <html> <head> <title> Basisschool De Regenboog </title> <style> img { position: absolute; left: 60%; } </style> </head> <body> <script> </script> <!-- header of your page, up until the content area --> <?php if (!isset($_POST["password"]) || $_POST["password"] != "123") { // no password or wrong password ?> <form action="" method="post"> <p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p> </form> <?php } else { // correct password ?> <!-- normal page content --> <a href="http:/www.youtube.com"><img src="Plaatjes/youtube.png" /></a> <?php } ?> <!-- footer of your page --> </body> </html> If the user has not submitted the correct password then the login form will show. Only until the user has entered the correct password (currently 123) then the youtube link will display. Quote Link to comment https://forums.phpfreaks.com/topic/300201-php-page-lock-put-password-to-enter-page/#findComment-1529406 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.