Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Access Registered Session Variables

Status
Not open for further replies.

scottmitchell

Programmer
Sep 7, 2002
11
US
I am having a problem accessing my session variables once a session is created.

Scenario:

1. I log the user in, successfully create a session using
session_start();
session_register( "SESSION_name" );

2. I then register my variables with data from the db in the format
session_register( "SESSION_username" );
$SESSION_username = $row["dbusername"];

Subsequently, on a different secured page, I can confirm that the session vars exist--
if ( session_is_registered( "SESSION_username" ) )
--but I cannot access the data in the variable.

Any assistance with syntax, troubleshooting, etc for accessing values would be most appreciated!

Thanks,

Scott
 
Version of PHP?

How are you attempting to access the information in the variable?

Have you considered scrapping session_register and using the $_SESSION array instead?

-Rob
 
Problem Update:

I have gone back and done some troubleshooting on my login-handler page, the page that actually handles the user login and initial session start. My $row variable contains the correct data, and after they are set, the $SESSION_username variable contains the correct data. However, when I attempt to immediately (from the login handler) attempt to access the variables via $_SESSION["SESSION_username"], it does not come back with a value.

skiflyer, I would be amiable to using the $_SESSION array for more than access if that is possible (I'm new to sessions in php, so I don't know that much about the $_SESSION array or sessions in general!).

Thanks!
 
Well first things first, if you're using $_SESSION["SESSION_username"] to access the variable, that's also how you should be setting it... and if you're using the $_SESSION array at all... you shouldn't be using session_register or session_is_registered.

Just session_start at the top of every page, and the $_SESSION array to both assign and access the variables.

-Rob
 
How would I check to see if the session is already started?

thanks,

scott
 
skiflyer,

I did get the session variables working thanks to your help!

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top