Jump to content

session problems


imarockstar

Recommended Posts

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.