I have a php page to which I pass a variable like: www.domain.com/test.php?id=1 Now, the file test.php includes nothing but <? include("config.php"); header("Location: http://www.redirect.com/main.php?domainID=$id"); ?> PHP: technically, this should work, and it does. The problem is that it works on one hosting company, not the other. Now, there is a problem somewhere. Can anybuide help me/guide me and tell me what I should ask/tell to my hosting company so that this works.
For that to work, you need "register_globals" on in php. To fix it, use the $_GET super global variable. <? header( 'Location: http://www.redirect.com/main.php?domainID='.$_GET['id']."\n"); exit; ?> PHP: Note that according to the HTTP spec, the Location header needs a newline char at the end. (but most browsers accept it anyway.) Also, after the header call, you can add an exit or die, so php exits immediatly.
Thanks a ton exam. I really appreciate your time and effort. It did solve the problem. Can you shoot me your paypal ID, for a small donation I would like to send as a thank you for your time.
Honey, add the following in your .htaccess and you should be fine too. Your version of php has register_globals turned off, so you can turn it on just by adding this in your .htacces. php_flag register_globals on I hope that helps.
Except that it's not a very recommendable practice to have register_globals turned on. But that is a life saver especially when you're dealing with legacy php code that relies on register_globals, until you can get the code updated.
exam, can you please guide why "Except that it's not a very recommendable practice to have register_globals turned on.". I have it on.
Because it's not safe. Anyone can manipulate variables within their script with the address bar. This can lead to SQL injection if you using sql or other nasty things such as your script getting read or deleted. ( Depends on how your script looks like ). I would definitely turn it OFF.
Actually, there's nothing unsafe about having register_globals "on" if you *always* initialize variables before using them. BUT, There is a lot of old code out there that doesn't initialize variables before using them, plus, why clutter up the global namespace with a bunch of unneeded variable and as adstracker says, allow anyone to set variables in your script using the address bar.
All the reasons adstracker stated are why PHP has been released with register_globals OFF by default for a while now... and also why the .htaccess trick might not work depending on how your web host has set things up.