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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.