Jump to content

[SOLVED] A very simple problem


Adam W

Recommended Posts

I have a bit of php code that passes an argument appended to a URL so that the new page can act on the information in the URL, only it doesn't. The same code running on a different server works perfectly. I've set up a quick demo the one that doesn't work is at http://www.keithj.ukfsn.org/test.php and the exactly the same code is at http://www.g-atou.com/test.php which works as I expect it too could someone be kind enough to explain what is happening?

 

BTW the code in test is

<?php
echo "You choose id<br>";
echo "<a href=\"test2.php?id=1\">id=1</a><br>";
echo "<a href=\"test2.php?id=2\">id=2</a><br>";
echo "<a href=\"test2.php?id=3\">id=3</a><br>";
?>

 

and in test2 is

<?php
echo "You choose $id<br>";
?>

 

Thanks

 

Adam

Link to comment
https://forums.phpfreaks.com/topic/37616-solved-a-very-simple-problem/
Share on other sites

http://www.keithj.ukfsn.org has register_global off while the other server (working server) have it on.

 

I would prefer to have it off, I would say I speak for majority of experienced PHP programmer here.

 

this is the code for you test2.php:

<?php
   $id = $_GET['id'];
   echo "You choose $id<br>";
?>

with register_global is on, PHP automatically create variables from POST,GET, and COOKIE, as you can see the $id variable magically appeared.

This can lead to confusion and open door for spamming, hacking, .. etc.

 

If you like to learn into detail, do a google on it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.