Jump to content

[solved]Session :(


reddavis999

Recommended Posts

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 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 session_start(); 

echo $_session["logged"]; 
?>

 

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

jobchaser.info

 

username:admin

password:password      or

 

username:john

password:red

 

Thanks for your help, Red

Link to comment
https://forums.phpfreaks.com/topic/50818-solvedsession/
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.