Page 1 of 1

Can't send value with Session

Posted: Sun Sep 05, 2010 6:11 pm
by md7dani
When I pass the value to another page with session_register the wrong value is printed. When I do the same thing by passing the value in the URL it works perfectly. So why can't I send it with Session??

I have another value, a $_COOKIE value. Maybe it's not possible to receive both a cookie and a session on the same page?

I use this code:

Code: Select all

//**** index.php ***
session_start(); // start up your PHP session! 

$username = "Superman";
session_register("username"); 

//**** shop.php ***
$name = $_SESSION['username'];
Do you see any errors?

Re: Can't send value with Session

Posted: Sun Sep 05, 2010 6:43 pm
by iansane
Hi,

session_register is deprecated depending on which version of php you are using.

http://php.net/manual/en/function.session-register.php

This is the newer way,

Code: Select all

//**** index.php ***
session_start(); // start up your PHP session!

$username = "Superman";
$_SESSION['username'] = $username;

//**** shop.php ***
$name = $_SESSION['username'];

They're all stored in array form ie.($_SESSION['username'], $_SESSION['password'], $_SESSION['email'] etc.) Like $_POST

Re: Can't send value with Session

Posted: Mon Sep 06, 2010 4:52 am
by wangxiaoyu
maybe your register_globals is disabled.