Thread: PHP session
View Single Post
Old 09-05-2007, 17:38   #1 (permalink)
reddavis999
Registered User
 
Join Date: Dec 2006
Posts: 3
PHP session

hey everyone. Ive recently started learning PHP and have made a simple login script for my project for college. The problem i am having is that the session does not seem to be carried from page to page. The session variable is called $_session["logged"]

Here is the code where the username and password is checked...

PHP Code:
<?php session_start();
        
    include (
"name.inc");

//connect to DB
    
mysql_connect ("$host","$username","$password")
        or die (
"couldnt connect");
    
mysql_select_db ("$database")
        or die (
"cannot select database");

//Information sent from the form

    
$myusername $_POST['username'];
    
$mypassword $_POST['password'];

    
    
$result mysql_query("SELECT * FROM $table where username='$myusername' and password='$mypassword'");
    
//gets number of rows with query above

    
$count mysql_num_rows($result);

//if the results matched then the number of rows will be 1...
    
    
if($count == 1){
        
$_session['logged'] = "hello";
        
header("location:session.php");
    }
    else {
        echo 
"wrong username and password";
    }


?>

And here is a file i made to check whether the information is being carried forward...
PHP Code:
<?php session_start();

echo 
$_session["logged"];
?>


Here is the website if you would like to see the problem.
jobchaser.info

username:admin
password:password

Thanks for your help, Red
  Reply With Quote