Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.