Jump to content


Photo

Assigning a reference?


  • Please log in to reply
2 replies to this topic

#1 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 28 July 2006 - 07:30 PM

I have the code:

echo "Location: $location<br>";
echo "Session: ".$_SESSION['location']."<br>";
$_SESSION['location'] = "";
echo "Location: $location<br>";

Which produces the output:

Location: main.php
Session: main.php
Location:

Why is this happening?  The only reason I can think of is that when I use the assignment operator, it's assigning a reference.  But I didn't think php did that.

How can I get it so that I take the value out of the session, but store it in a temporary variable?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 July 2006 - 07:37 PM

Do you have a setting called register_globals enabled? You can check this by running this:
<?php
phpinfo();
?>

Scroll down looking for the register_globals setting, check that the two columns to the right are set to Off

if it is enabled this your problem as you can use $_SESSION['location'] and $location to access the session data for location.

#3 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 28 July 2006 - 07:41 PM

Hah.

Half the time I do things like:

$num = $_SESSION['num'];

To make it easier to code.

Thanks, that fixed the problem.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users