I have created a member login page and now I am working on a restricted 'Member's Only Section'. I am fairly new to mySQL and I am also practically trying to teach myself. My question is related to authorizing someone who has just logged in, to allow them to go to that restricted section. Vice versa, if they are not logged in, they should not be able to access it or find an error. Below is the code that I have from my login page and also the code for the restricted section...
echo "Welcome."; //Successful
echo "<br>";
echo "<a href='thankspage.html'> Click here </a> to continue to the Member Page."; // creates a link to go to.
$sql = " INSERT INTO Login (loginName,loginTime)
VALUES ('$username', NOW() ) "; // creates the login time.
$result = $mysqli->query($sql) or die ($mysqli->error); // shoots an error if i did something wrong.
$_SESSION[‘logname’] = $userlogin;
$_SESSION[‘auth’]=”yes”;
Below is the code for the information section:
if ($_SESSION[‘auth’] != “yes”)
{
header("Location: membership.php");
exit();
}
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE)
or die("Failed to connect");
$sql = "SELECT firstName,lastName FROM Member
WHERE loginName=’{$_SESSION['logname']}’ ";
$result = $mysqli->query($sql) or die($mysqli->error);
My main issue is that I can access this page whether I am logged in or not... is the variable $_SESSION['auth'] not a global variable?
session_start()at the beginning of both scripts?var_dump($_SESSION)show when someone goes to the second page when not logged in?