imarockstar Posted August 19, 2008 Share Posted August 19, 2008 my sessions are not working ... can someone check my code to see what im doing wrong ... page the session starts : $username = ($_POST['username']); $password = md5($_POST['password']); // Encrypts the password. $q = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); // Checks to see if anything is in the db. if ($r == 1) { // There is something in the db. The username/password match up. session_register('logged'); $_SESSION['logged'] = 1; //$_SESSION['logged'] = 1; // Sets the session. header("Location: resume"); // Goes to main page. //echo "your logged in"; exit(); // Stops the rest of the script. } else { // Invalid username/password. exit("Incorrect username/password!"); // Stops the script with an error message. } page where you are not supposed to see the content if you dont have a session .. but for some reason ... no matter what . you can still see the page : <?php include("conf.inc.php"); // Includes the db and form info. session_start(); // Starts the session. if ($_SESSION['logged'] != 1) { // There was no session found! header("Location: login.php"); // Goes to login page. exit(); // Stops the rest of the script. } echo "This is the main page!"; echo " "; echo "<a href=\"logout.php\">Logout?</a>" ?> do i have something screwed up with the session calls ? Link to comment https://forums.phpfreaks.com/topic/120409-session-problems/ Share on other sites More sharing options...
revraz Posted August 19, 2008 Share Posted August 19, 2008 Remove session_register in the first page. In both pages, put session_start(); as your first line of code Link to comment https://forums.phpfreaks.com/topic/120409-session-problems/#findComment-620525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.