Adam W Posted February 8, 2007 Share Posted February 8, 2007 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 More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/37616-solved-a-very-simple-problem/#findComment-179904 Share on other sites More sharing options...
Adam W Posted February 8, 2007 Author Share Posted February 8, 2007 Thanks very much Why is it a good idea to have register_global off? Link to comment https://forums.phpfreaks.com/topic/37616-solved-a-very-simple-problem/#findComment-179908 Share on other sites More sharing options...
hvle Posted February 8, 2007 Share Posted February 8, 2007 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. Link to comment https://forums.phpfreaks.com/topic/37616-solved-a-very-simple-problem/#findComment-179917 Share on other sites More sharing options...
Adam W Posted February 8, 2007 Author Share Posted February 8, 2007 Thanks Link to comment https://forums.phpfreaks.com/topic/37616-solved-a-very-simple-problem/#findComment-179970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.