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
$_SESSION[] variable not being passed
Moderator: General Moderators
Re: $_SESSION[] variable not being passed
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
I don't understand, isn't that what I said I did?cdpace wrote:...it needs to be the first line of code in your document.
Re: $_SESSION[] variable not being passed
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 ...
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
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.
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.