Session variable as array lost between pages - Solved

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
dabra
Forum Newbie
Posts: 2
Joined: Thu Sep 13, 2007 1:35 pm

Session variable as array lost between pages - Solved

Post 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]
Last edited by dabra on Sat Sep 15, 2007 2:39 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
dabra
Forum Newbie
Posts: 2
Joined: Thu Sep 13, 2007 1:35 pm

Session array as variable lost ... - Solved

Post by dabra »

Problem solved. Thank you very much! (And apologies for the incorrect format of the first post.)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

No problem. :-D Glad I could help.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply