woodsonoversoul Posted July 9, 2009 Share Posted July 9, 2009 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 https://forums.phpfreaks.com/topic/165340-weird-stuff-returned-with-_sessionusername/ Share on other sites More sharing options...
woodsonoversoul Posted July 9, 2009 Author Share Posted July 9, 2009 Fixed it by switching up the quotes, ie: <body onload="getUserInfo(' <? echo $_SESSION['username']; ?> ')"> Link to comment https://forums.phpfreaks.com/topic/165340-weird-stuff-returned-with-_sessionusername/#findComment-871936 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2009 Share Posted July 9, 2009 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 https://forums.phpfreaks.com/topic/165340-weird-stuff-returned-with-_sessionusername/#findComment-871941 Share on other sites More sharing options...
woodsonoversoul Posted July 9, 2009 Author Share Posted July 9, 2009 Thanks PFMaBiSmAd Link to comment https://forums.phpfreaks.com/topic/165340-weird-stuff-returned-with-_sessionusername/#findComment-871983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.