Jump to content

weird stuff returned with $_SESSION['username']


Recommended Posts

Hello all. I'm just getting started with session variables and have run into this problem: when I use the line

<body onload="getUserInfo(" <? echo $_SESSION['username']; ?> ")">

I get

<body onload="getUserInfo(" danwoods="" )="">

and I feel like I should be getting

<body onload="getUserInfo(" danwoods" )">

I don't know where the equal signs or extra quotations are coming from. I use the session username variable elsewhere on the page and it works fine. Any ideas?

 

Also, like I said, I'm a sessions newb, but, you have to start a session on every page you want to use session variables, but you only have to end the session once (ie. on logout). Is that correct?

 

danwoods=""

 

It is likely that you have an if() conditional test in your php code that is only using a single = sign and it is changing $_SESSION['username'] rather than testing what is in it.

 

A session is just a container that holds variables that you want to exist between page visits. If the method you are using to detect if someone is logged in is the existence of a specific session variable with a specific value, then yes unsettling that session variable or destroying the session will work to log someone out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.