PHP – Turn register globals on off using htaccess

Problem:

My application is hosted on a server where php has register_globals set to on in php.ini. But using register_globals = on makes code error prone and is dangerous to use.
I want to turn it of for my application regardless of what is its setting for other applications.
Since the value of register_globals cannot be set at run time bu using ini_set, how can I do it?

Solution:

Use htaccess file to control this behaviour. Create a file named .htaccess in root directory of your application and write the following line in it:

php_flag register_globals off

Thats all you need to do.

You can verify this by creating a phpinfo() file. Suppose your server has register_globals set to on and you have turned it off using above syntax.

phpinfo() will show the local value as off and master value as on.

Note: Of course, this will work only if your apache configuration allows to override htaccess settings.

Most Commented Posts

FAQ, php

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

One Response to “PHP – Turn register globals on off using htaccess”

Leave Comment

(required)

(required)


9,565 spam comments
blocked by
Akismet