$_SESSION[] variable not being passed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
allasso
Forum Commoner
Posts: 28
Joined: Fri Nov 28, 2008 1:24 pm

$_SESSION[] variable not being passed

Post 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
cdpace
Forum Newbie
Posts: 1
Joined: Sat Nov 29, 2008 5:32 pm

Re: $_SESSION[] variable not being passed

Post 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.
allasso
Forum Commoner
Posts: 28
Joined: Fri Nov 28, 2008 1:24 pm

Re: $_SESSION[] variable not being passed

Post 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?
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: $_SESSION[] variable not being passed

Post 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'];
 
?>
allasso
Forum Commoner
Posts: 28
Joined: Fri Nov 28, 2008 1:24 pm

Re: $_SESSION[] variable not being passed

Post 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.
Post Reply