Enabling and Disabling the PHP register_globals Directive
The register_globals directive in PHP automatically turns incoming request variables (from forms, cookies, and URLs) into global variables. While this may simplify coding, it introduces serious security risks. For this reason, register_globals was deprecated in PHP 5.3 and removed entirely in PHP 5.4 and later.
How to Enable or Disable register_globals
Section titled “How to Enable or Disable register_globals”1. Using a Custom php.ini File
Section titled “1. Using a Custom php.ini File”Edit or create a php.ini file in your application directory:
; Enable register_globalsregister_globals = On
; Disable register_globalsregister_globals = Off2. Using .htaccess
Section titled “2. Using .htaccess”On Apache servers, you can override the directive in .htaccess:
# Enablephp_flag register_globals On
# Disablephp_flag register_globals Off3. Using .user.ini
Section titled “3. Using .user.ini”If your hosting environment supports .user.ini, add:
register_globals = OffBest Practices
Section titled “Best Practices”- Always keep
register_globalsdisabled to protect your application. - Use
$_GET,$_POST, and$_COOKIEsuperglobals explicitly instead of relying on automatic variable creation. - If you are running PHP 5.4 or later, this directive is no longer available.