Forum Moderators: coopster

Message Too Old, No Replies

Clarification of Global Variables OFF

whats the deal

         

ukgimp

3:17 pm on Oct 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK I have hacked a script that was wriiten for global variables = on.

It is going to take me some time to get it sorted but what I wish to know is is using the $_GET['var'] and the like backward compatible?

phphmyadmin seems to work in both situations so I am a little confused.

As it stands I have to do the old:

$var = $_POST['var']

but if I ever have to adapt to a host that has register on I dont want ohave to spend a week sorting it out.

Cheers

jatar_k

4:51 pm on Oct 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you use $_POST['var'] or $_GET['var'] it will work just fine.

Essentially all register_globals does is extract [ca.php.net] or import_request_variables [ca.php.net]. The original vars are there in both cases but you can't access them by $var (without intervention) with register_globals off.

The only time $_POST, or the like, will cause an issue is if your version is less than 4.1.0 and then you would need to use $HTTP_POST_VARS, $HTTP_GET_VARS etc.

coopster

5:17 pm on Oct 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




but if I ever have to adapt to a host that has register on I dont want ohave to spend a week sorting it out.

A tip for you:
You can toggle whatever your host has for this directive by simply adding an .htaccess file to your php code directories with a single line to turn the register_globals on/off:

php_flag register_globals off

Then you won't have to modify your code ;)

This thread [webmasterworld.com...] has a good discussion about register_globals.

ukgimp

8:01 am on Oct 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks JK and Coop'

Cheers

ukgimp

9:04 am on Oct 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Register Globals [ca.php.net] and why it is best to have it set to OFF.

Coopster

I found this on my travels wrt your method of turning register globals on and off on your host. If you are on a vhost you need to have a line or two in your httpd.conf file.

<Directory /whatever/>
AllowOverride Options
</Directory>

(AllowOverride All will also work.)

Cheers

coopster

11:52 am on Oct 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Right on. Most (all) shared hosting companies aren't going to allow access to their httpd.conf file so any host worth their salt had better at least allow override directives, which means they would already have this directive entry for you when you initially pay them and setup your account.