2

One of my PHP pages, which runs on a remote server allegedly with PHP 5.2 installed, receives a POST request with a set "passcode" key and then, as it seems, the most strange things may happen. In the following code, "passcode" of the POST request is redefined to make value tracking simpler for you guys, but in tests it still produces the supernatural output indicated in the comments.

$_POST["passcode"] = "hi";
$_SESSION["passcode"] = "hello";

echo $_SESSION["passcode"] . '<br />'; // prints "hello"
$passcode = $_POST["passcode"];
echo $_SESSION["passcode"] . '<br />'; // prints "hi"

EDIT: So looks like it's about register_globals. Hence is another question:

Is there any way to turn this behavior off if I don't have access to the php.ini file on the server I'm running the code on?

3
  • With only that in the receiving file you have those results, or when it's through your entire, existing code? Commented Jan 20, 2012 at 13:26
  • That's odd.<br /> Is it the same when you comment out the fifth line? Commented Jan 20, 2012 at 13:27
  • @MetalFrog That POST receiving php file is the only place where I've tested it so far. Commented Jan 20, 2012 at 13:31

5 Answers 5

8

Clearly, session variables are registered as globals.

Sign up to request clarification or add additional context in comments.

Comments

7

Smells like register_globals

If you can't edit your php.ini file, you can disable this setting in .htaccess file, as described here

Comments

2

Session Variables may be configured to be handled as Global Varibales and so can be accessed through $_SESSION["passcode"] as well as $passcode. check your PHP Configuration (register_Globals)

Comments

2

One possible reason it is possible is somewhere you have written

$_SESSION['passcode']=&$passcode;

Comments

-1

Change the name of the variable

$passcode

to something else.?

1 Comment

I'd rather change my hosting provider than my programming style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.