vijayjoshi.org - php | javascript | ajax | and all things web

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

Posted in : FAQ, PHP
Tags:

1 Comment to “PHP – Turn register globals on off using htaccess”

Add Comments (+)

  1. Kamal says:

    Thanks, good coding

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

55,801 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>