How to fix PHP register_globals errors

If you are using an old version of PHP, it is likely that you have seen errors as follows: PHP Fatal error: Directive ‘register_globals’ is no longer available in PHP in Unknown on line 0

“PHP Fatal error: Directive ‘register_globals’ is no longer available in PHP in Unknown on line 0”

“PHP Fatal error: Directive ‘register_globals’ is deprecated in PHP 5.3 and greater in Unknown on line 0”

Now, register_globals is a php setting which automatically fetches values from GET and POST forms into local variables inside your PHP script. This is a security risk, and hackers can easily guess the values and variables. Hence, from version 5.3 of PHP, this directive has been removed from PHP and is no longer supported.

How to solve the register globals issue in PHP

If you get any of the above errors, chances are that you currently are being hosted on a server with PHP version above 5.3 or the web hosting company transfered your site from a server with old PHP to a server with latest PHP. In such cases,  you need to search for a file named php.ini under your domain and comment the following line if found or change the value to 0

# register_globals=1;

or

register_globals=0;

 

Sometimes the same will be present in any .htaccess file. Remove the line if found or change the value to off or ‘0’.

# php_flag register_globals on

or

php_flag register_globals off

You can do the same via cpanel also. Login to your cpanel account using the cpanel login details. Once in the dashboard, go to Software -> Select PHP Version.

 

php2

In this new page, you can manage the PHP settings. Click on ‘Switch to PHP Options’.

 

php modules

 

It will take you to a page where you can turn register_globals on or off. Choose Off and hit ‘Apply’. Scroll down and click ‘Save’.

 

php11

You can confirm the successful change in value by placing a phpinfo page in your site. Go to the public_html folder of your domain, and create a file named, say info.php, and enter the following contents to it.

<?php

phpinfo();

?>

 

My domain is copablog.com, now I can access the file as http://copablog.com/info.php. I can see that register_globals shows as off there.

 

register globals settings in phpinfo

 

Now, execute your script again and see if the error vanishes !!!

 

 

Was this helpful?

Thanks for your feedback!

Gustavo Bastos

Leave a Reply

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