URL not grabbing ?

Posted By: gostly ()
Posted On: 2004-Jul-07 23:09

i just switched servers, and before everything worked out just fine...but now i have pages like...

profile.php?id=2

but it's treating it as if it's not picking up the $id after the ?...although it used to on our other server...so i was thinking my settings arent right or maybe im using the wrong version of something, my current php version is 4.3.6...but i dont know where to look to try to fix the problem


Posted By: jcokos (Staff)
Posted On: 2004-Jul-08 20:40

Your new server is (correctly) setup with REGISTER GLOBALS turned off.

With that off, variables in the URL, such as your "id=2" are not automatically turned into $id. Rather, you'll have to reference them by the global variable $_GET .... ie:

$_GET['id'] should be set to "2" now.

You can get around this by doing something like this at the top of your script:



Code: [copy]





However, this defeats the purpose of having the automatic registration of those variables off. You should do some error and sanity checking on them before making them global as I showed above.


Posted By: mincklerstraat ()
Posted On: 2004-Sep-16 18:37

might also work with :


Code: [copy]




and note the two $$ in front of var.
jcokos's might be safer though
If you can't find any nice, central place to put this, like in a config file or something, you can look at the auto prepend stuff in php, put that in your .htaccess file.

check to see if your script has got a new version that doesn't have to work with register globals turned on - if you can upgrade, you will probably be more secure, and won't have to do all this.