Hi. How can I password-protect a single file using PHP? I want a login prompt to show up utilizing a username and password set by PHP variables to view the web page's contents. I don't want it to be able to be viewed by source code or easily h4x0red. I want it to be like if a user wants to see 1.php they'll have to enter right login info to view contents. Please assist.
you can : - make a form - get the variables (username + password) - test if the username and password match - show the real content The form is just simple HTML , In the Form action you put the page it self . To get the variable : $_POST[user] , $_POST[pass] // if the form method is POST . Then you can test : $user = "test"; $pass = "test_"; if $_POST[user] == $user && $_POST[pass] == $pass ... you show the real content .. else show the form again with the error message .
it is also important that you store the restricted file outside of your document root, so that it is not possible to access the file directly (bypassing the PHP script) from the browser.