Passing Session Variables Help

A

Anonymous

Guest
Hi,

In my first page, i have this code :

$name = "Name";
session_start();

session_register('User');
$User = $name
$sessionID = session_id();

header("Location:http://www.mysite.com/sms.php?PHPSESSID=$sessionID");



And on the other page, i tried to retrive the variable $User which i don't know how to. Can someone tell me how can i retrive the variable ?

Thanks
 
First of all you should START with session_start()

so that should be at the top of your page before any other code is send. There is also a problem how you register your session vars. The correct way to do it is this:

$whatever = 'something';
$_SESSION['whatever'] = $whatever;

You can do view the session var with:

echo $_SESSION['whatever'];

Good luck!

ps. Maybe you should read the part on sessions on php.net
 
Thanks. Actually, now i know where my problem is. I have to "session_start" again at the new page where my link is to.

By the way, can we use $HTTP_POST_VAR & $HTTP_GET_VAR ?

Is it better?
 
If you are working with sessions, retrieving session variables with $HTTP_POST_VAR & $HTTP_GET_VAR ... makes no sense!
Use this for session variables:
PHP:
$HTTP_SESSION_VARS['whatever'];
$_SESSION['whatever'];
session_name('whatever');
 
Back
Top