Session variables not carrying over to next page

Thread Solved

Join Date: Jun 2006
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Session variables not carrying over to next page

 
0
  #1
Oct 14th, 2007
Howdy all,

I'm making an authentication script using sessions variables, but the varible seems to disappear when trying to access it from another page.

A simple form on the home page takes a user name and password, it then goes to an authentication page. The authenticate page is making a match and setting the session variables. I have tested this part and know that for sure. The authentication page then redirects in 2 seconds back to the originating page by a meta refresh. In this case, its the index page, but the index page does not recognize the session variable. Here is the code on the index page:


if ($_SESSION["authenticated"]=="YES")
{
echo "Hi " .$_SESSION["user_name"];
}
else
{
?>

HTML form code here.

<?php
}
?>



It supposed to acknowledge the user, or put the log in form on the page, but it doesn't recognize the varible. Can anyone help? I've googled and looked at the code over and over, but can't see anything wrong.


Also, I'm using PHP 4.2.?, so I should not have to register the session variables as recommended for version 4.1 and above, correct?




Thanks,

Gil
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Session variables not carrying over to next page

 
0
  #2
Oct 14th, 2007
did you put session_start(); at the beginning of the second page
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Session variables not carrying over to next page

 
0
  #3
Oct 14th, 2007
yeah,and try to echo the session to check if it exists
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Re: Session variables not carrying over to next page

 
0
  #4
Oct 14th, 2007
Yes, I did have the
  1.  
  2. session_start();
and it does show the session variables on the authentication page when I echo the

  1.  
  2. $_SESSION["authenticated"]
variable. It returns 'YES', so I know its making the query on the mySQL database and matching with the submitted data.

When I redirect back to the index page, it will not echo the authenticated or user_name variable.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Session variables not carrying over to next page

 
0
  #5
Oct 14th, 2007
you should have session_start(); on the index page as well so you can access the session values.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Re: Session variables not carrying over to next page

 
0
  #6
Oct 15th, 2007
Thanks! That did it!

I'm more familiar with ASP session variables because that's what I use at work. This was the first time I have used a PHP session script, I though you only needed the session_start() once.

Much thanks, I have spent way too much time trying to figure out what was wrong!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC