Very newbie question about session variables

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
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

Very newbie question about session variables

Post by noguru »

Hi all,

I can't get my other pages to read session variables set on one page.

I'm using PHP Version 4.0.4. I have tried $HTTP_SESSION_VARS but found $_SESSION to work as well with this version.

Here's the code for page1.php:

<?php
session_start();
$_SESSION['uid']=24;
echo $_SESSION['uid'];
?>


and for page2.php:

<?php
session_start();
echo $_SESSION['uid'];
?>


On page1.php it echos the value of the Session variable, but on any other page it does not. I know I'm missing something, my code seems just too easy.

Any help is appreciated!

Thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

$_SESSION isn't working as it would in v4.1 up - you are simply creating an array called $_SESSION which is not special in any way. You need to use $HTTP_SESSION_VARS instead. Also look at the session_register() function.

Mac
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

Post by noguru »

thanx a lot twiggie! it's working (finally)!!! may your brain never rotten and your generosity never be forgotten! :roll:
Post Reply