Register Global setting checking

When we submit a form or pass variables by query sting or read from Cookies the variables will be available by default if the register_globals is set ON in php.ini file. But this way all these variables , or the user data will interfere with the code of the page so many time the register_globals setting will be kept in Off condition. Keeping it on is also a security problem if proper care is not taken.

We can check the status of register_globals from php info page or by checking the register_global value. This will return TRUE or FALSE based on the setting. So the following code will tell us about the status of register_global.
if (ini_get('register_globals')){echo "<font color=red>Registor global is ON</a><br>This is a security issue, please change settings inside your php.ini file</font>";}
else{echo "Register global is OFF";} 
This setting of global variables is kept inside php.ini file and is not available for edit in shared hosting plans. So you may have to contact your host to change the setting. If you are using your local machine or in windows then search for php.ini file inside your windows directory.

If the global variable is kept OFF then we can access the variables of a form submitted like this
$username=$_POST['username'];
Here the form is submitted by POST method and similarly we can get the values for GET method or variables from the URL, server variables etc.
$username=$_GET['username'];
Here is a code example for making available the variables if register global is off
while (list ($key,$val) = each ($_POST)) {
$$key = $val;}
But note that by using above code you are defeating the very purpose of keeping the register_global off for security reasons.
In version PHP 5 and above by default register_global is kept OFF.
Sitemap Form Form post back data
Checking Data Radio buttons
PHP sticky form using listbox
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Jamal Faiye

    26-08-2013

    Very usefull

    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer