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
Old 09-05-2007, 18:30   #2 (permalink)
theRemix
Battery Chicken
 
theRemix's Avatar
 
Join Date: Apr 2007
Location: Hawaii
Posts: 82
Send a message via AIM to theRemix Send a message via MSN to theRemix
try

Code:
$_SESSION['logged']
  Reply With Quote
Old 10-05-2007, 10:56   #3 (permalink)
mx
fucksocks™
 
mx's Avatar
 
Join Date: Jun 2005
Location: in the boosh
Posts: 1,611
are you sure the count is equal to one?
__________________
  Reply With Quote
Old 10-05-2007, 11:40   #4 (permalink)
reddavis999
Registered User
 
Join Date: Dec 2006
Posts: 3
Theremix: thanks but it didnt change anything

max h: yer, im pretty certain. i created another test account to double check. username:john password:red
  Reply With Quote
Old 10-05-2007, 12:08   #5 (permalink)
reddavis999
Registered User
 
Join Date: Dec 2006
Posts: 3
ah, it has been fixed. $_session, needs to be all in capitals. Its always the little things that cause the problems.
  Reply With Quote
Old 10-05-2007, 16:12   #6 (permalink)
combat sheep
Trained to Kill.
 
combat sheep's Avatar
 
Join Date: Oct 2006
Location: Southport, UK
Posts: 308
Send a message via MSN to combat sheep
Quote:
Originally Posted by reddavis999
ah, it has been fixed. $_session, needs to be all in capitals. Its always the little things that cause the problems.
always use capitals for superglobals in PHP
  Reply With Quote
Old 10-05-2007, 21:56   #7 (permalink)
theRemix
Battery Chicken
 
theRemix's Avatar
 
Join Date: Apr 2007
Location: Hawaii
Posts: 82
Send a message via AIM to theRemix Send a message via MSN to theRemix
Quote:
Originally Posted by reddavis999
Theremix: thanks but it didnt change anything

max h: yer, im pretty certain. i created another test account to double check. username:john password:red

your wc
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8