Note that there are some explanatory texts on larger screens.

plurals
  1. POpassword validation for page not working
    text
    copied!<p>the login.php form and password.php is working but the validation for entering a site is not</p> <p>code for "passwords.php"</p> <pre><code>&lt;?php $USERS["username1"] = "password1"; $USERS["username2"] = "password2"; $USERS["username3"] = "password3"; function check_logged(){ global $_SESSION, $USERS; if (!array_key_exists($_SESSION["logged"],$USERS)) { header("Location: login.php"); }; }; ?&gt; </code></pre> <p>login.php</p> <pre><code>&lt;?php session_start(); include("passwords.php"); if ($_POST["ac"]=="log") { /// do after login form is submitted if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted $_SESSION["logged"]=$_POST["username"]; } else { echo 'Incorrect username/password. Please, try again.'; }; }; if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not echo "You are logged in."; //// if user is logged show a message } else { //// if not logged show login form echo '&lt;form action="login.php" method="post"&gt;&lt;input type="hidden" name="ac" value="log"&gt; '; echo 'Username: &lt;input type="text" name="username" /&gt;'; echo 'Password: &lt;input type="password" name="password" /&gt;'; echo '&lt;input type="submit" value="Login" /&gt;'; echo '&lt;/form&gt;'; }; ?&gt; </code></pre> <p>i cant make this part work</p> <p>validation for page:</p> <pre><code>&lt;?php session_start(); /// initialize session include("passwords.php"); check_logged(); /// function checks if visitor is logged. ?&gt; </code></pre> <p>page code goes here</p> <p>what am i doing wrong? the validation does not check if the user is logged in or not. it just proceeds to the page.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload