User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,604 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,673 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1677 | Replies: 5 | Solved
Reply
Join Date: Jun 2006
Location: College Station, TX
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Session variables not carrying over to next page

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 539
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 54
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Session variables not carrying over to next page

  #2  
Oct 14th, 2007
did you put session_start(); at the beginning of the second page
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 503
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 67
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Session variables not carrying over to next page

  #3  
Oct 14th, 2007
yeah,and try to echo the session to check if it exists
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Jun 2006
Location: College Station, TX
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Re: Session variables not carrying over to next page

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

 
$_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  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 539
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 54
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Session variables not carrying over to next page

  #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  
Join Date: Jun 2006
Location: College Station, TX
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Re: Session variables not carrying over to next page

  #6  
Oct 14th, 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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 7:26 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC