Page 1 of 1
$_SESSION[] variable not being passed
Posted: Fri Nov 28, 2008 2:20 pm
by allasso
I have had no success in passing the $_SESSION["var"] array to other pages. I have included code that looks something like below, with session_start() at the very top of the script, and not html above it. (no output sent before session_start() ). I have also included session_start() on all pages I wish to retrieve the variables from. No success.
<?php
session_start();
$_SESSION["var"] = 'hello world';
?>
any ideas?
Thanks, Allasso
Re: $_SESSION[] variable not being passed
Posted: Sat Nov 29, 2008 5:33 pm
by cdpace
The Problem is that you are putting the session_start() after some code, it needs to be the first line of code in your document.
Re: $_SESSION[] variable not being passed
Posted: Sat Nov 29, 2008 6:05 pm
by allasso
cdpace wrote:...it needs to be the first line of code in your document.
I don't understand, isn't that what I said I did?
Re: $_SESSION[] variable not being passed
Posted: Sun Nov 30, 2008 5:07 am
by Stryks
I'm assuming that you aren't getting an error, just that the data isn't in the session array?
What code are you using to try and access the session? I'd imagine something like ...
Code: Select all
<?php
session_start();
echo 'Session value is: ' . $_SESSION['var'];
?>
Re: $_SESSION[] variable not being passed
Posted: Sun Nov 30, 2008 4:02 pm
by allasso
I found out my problem. I was using integers for keys in the $_SESSION[] array. Apparently that does not work, unless they are mixed with alpha characters. I couldn't find any documentation on that, but maybe it's in there somewhere.
When I posted I was at a different computer, so I just gave a generic example, using "var" as a key. I see it is important to post code exactly the way it was written.
Thanks all.