Re: Session hell: register_globals off
| From: | trlists at clayst dot com | Date: | Sun, 04 Apr 2004 21:12:59 +0000 |
| Subject: | Re: Session hell: register_globals off | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182299@lists.php.net to get a copy of this message | ||
On 4 Apr 2004 Randall Perry wrote:
> Solved my main problem. I was assuming that variables registered with
> $_SESSION were passed by reference. Apparently they're passed by value.
*Passing* by value or by reference has to do with function parameters,
not array values. However you can assign one variable as a reference
to another, see http://www.php.net/manual/en/language.references.php.
When you enter a line of code like:
$_SESSION['order'] = $order;
you are doing a regular assignment. To use a reference instead, use:
$_SESSION['order'] =& $order;
The data will be passed this way to the next session. For example, try
this (substitute your server name in the header() call):
test1.php:
<?php
session_start();
$test1 = "";
$_SESSION["Test1"] =& $test1;
$test1 = "this is test1";
header("Location: http://localhost/olm/test2.php");
?>
test2.php:
<?php
session_start();
var_dump($_SESSION);
?>
The output on the second page will be something like this (I'm using
xdebug so this is not raw var_dump() output):
array
'Test1' => 'this is test1'
--
Tom