Page 1 of 1

Session variable as array lost between pages - Solved

Posted: Fri Sep 14, 2007 1:35 pm
by dabra
scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello. 

Can someone please tell me why all my session variables are passed from one page to another successfully except those which have been assigned an array?

I've now reduced the code to the simplest and it still doesn't work! This page outputs the array successfully, but the second page doesn't 

I'm testing on a remote server which has register_globals on (if that's relevant).

Thanks a lot.

Code: Select all

<?php session_start();

$_Session['mpl'] = array();

$_Session['mpl'][0] = 'hello';

print_r($_Session['mpl']); 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<a href="http://www.mydomain.com/session_array_test_2.php" class="bold">Go To session_array_test_2</a>
</body>
</html>
The second page just has this and a similar link back to the first page.

Code: Select all

<?php session_start();

if (!isset($_SESSION['mpl'])) {echo 'Variable not set!  ';}
else { print_r($_Session['mpl']); } 

?>

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Sep 14, 2007 1:43 pm
by s.dot
Variables are case sensitive.

$_SESSION != $_Session

EDIT| I should also note that $_Session is just a regular variable, and will be lost at the end of the script's execution. However, $_SESSION will reference the session and will be passed between pages, in your code.

Session array as variable lost ... - Solved

Posted: Sat Sep 15, 2007 2:36 am
by dabra
Problem solved. Thank you very much! (And apologies for the incorrect format of the first post.)

Posted: Sat Sep 15, 2007 2:41 am
by s.dot
No problem. :-D Glad I could help.