SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

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.

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.

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(register_globals) {
echo "Registor global is ON";}
else{echo "Register global is OFF";}



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.

Discuss this tutorial at forum


Further readings
All form components validation with post back and data locking
Checkbox
How to retain form data if validation fails?
How to retain data of a text box after submitting
Retaining status of a check box
Updating checkbox value from & to a table record.
Retaining selected data of a period button of a form
Retaining selected data of a drop down list box of a form
Validating Date: Checking if date exist
Email address validation in a form
PHP Form Validation
is_numeric to check numeric numbers
ctype_alnum to check alphanumeric characters data
ctype_alpha to check alphabetic characters data
How to take care of form & query string variables if Register global is OFF?














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.