943,660 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 6891
  • PHP RSS
Oct 14th, 2007
0

Session variables not carrying over to next page

Expand Post »
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
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
gil857 is offline Offline
35 posts
since Jun 2006
Oct 14th, 2007
0

Re: Session variables not carrying over to next page

did you put session_start(); at the beginning of the second page
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Oct 14th, 2007
0

Re: Session variables not carrying over to next page

yeah,and try to echo the session to check if it exists
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Oct 14th, 2007
0

Re: Session variables not carrying over to next page

Yes, I did have the
PHP Syntax (Toggle Plain Text)
  1.  
  2. session_start();
and it does show the session variables on the authentication page when I echo the

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 0
Light Poster
gil857 is offline Offline
35 posts
since Jun 2006
Oct 14th, 2007
0

Re: Session variables not carrying over to next page

you should have session_start(); on the index page as well so you can access the session values.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Oct 15th, 2007
0

Re: Session variables not carrying over to next page

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!
Reputation Points: 11
Solved Threads: 0
Light Poster
gil857 is offline Offline
35 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Coloring text
Next Thread in PHP Forum Timeline: session variable error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC