retrieving 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
feiticeir0
Forum Newbie
Posts: 8
Joined: Tue Nov 05, 2002 1:33 pm
Location: Castelo Branco, Portugal

retrieving session variables

Post by feiticeir0 »

Hi !!

how can i retrieve a session variable ?

after doing this:
<a href="something.php?PHPSESSID=<?php $HTTP_SESSION_VARS["variable"] ?>&something=something">

how can i retrieve the session variable in the other document ?

regards!!
Rincewind
Forum Commoner
Posts: 27
Joined: Thu Nov 21, 2002 11:15 am
Location: Norway

Post by Rincewind »

I'm not sure if I understood your question correctly but....
You can assign variable to $HTTP_SESSION_VARS

Code: Select all

<?php
$HTTP_SESSION_VARS&#1111;'something'] = $something;
?>
Then on any other page using that session this variable is accessible as

$HTTP_SESSION_VARS['something']

Hope that helped.

Rincewind_the_Wizzard
persaltier
Forum Newbie
Posts: 3
Joined: Wed Dec 18, 2002 10:50 pm
Location: NYC

Post by persaltier »

to retrieve the variable on subsequent pages, you'll need to first invoke the session for that page...

you'd do this by starting the session at the top of the page --->

Code: Select all

<?php
session_start();
?>
you'll then refer to the session variable using the $_SESSION superglobal if you're using PHP 4.1 + or $HHTP_SESSION_VAR if you're using an older version.

Code: Select all

<?php
echo $_SESSION[yourvar];  \\ echos your variable in 4.1+
echo $HTTP_SESSION_VAR[yourvar]; \\   <4.1
?>
Post Reply