php sessions not working
- Started
- Last post
- 6 Responses
- mikotondria3
hi all..
I have an admin page for a site where the admin people have the ability to 'log in as user'.
They select the user, then it redirects to a page where a session variable sets the userid and username, and then boots them onto the ria which goes about populating its info based on the session variables for that user..On the page before the admin is redirected to the ria app, I literally just put the user id into the session array, and I see it on the page...
echo '<br>User Id: '.$_SESSION['theuserid'];
However when we arrive at the next page with the ria on, (and I've tried a meta-refresh, a header(...), AND an href, the session variable just isnt remaining...
I have a script that literallly just reads and outputs the session variable for testing, with a line identical to the one above, and it shows blank. The session isnt being set..
Any ideas ?Thanks each.
- bezul5550
did you start session? do you have session_start();?
- mikotondria30
ah, it's cool.
Yeh, I'd got session_start() at the top and bottom, but I was trying to read the session variable by calling my script from http://domain, not http://www.domain, which is where I had set the script.
Odd, really but now it works and the session persists, just not between http:// and http://www..
- bezul5550
just keep it at the top, dont repeat; check your globals
- mikotondria30
yes, I don't have a clue why I typed 'and bottom' there.
session_start is indeed only at the top, before all else.
Thanks!
- bezul5550
for testing try echo session_id(); - it really helps sometimes :)
- mikotondria30
yeh right - I mean for me, php is something I really hardly have to think about, I just think it and type it so when a little thing like this comes up it really throws me and I have horrific visions of every other backend I've done suddenly not working because all my principle understanding was wrong.
cheers :)