web 2.0

How to get variable with register_global = On/Off

How to get variable with register_global = On/Off Check php configuration register_global = On/Off using phpinfo();

ShotDev Focus:
- Get variable register_global = On
- Get variable register_global = Off
- Change register_global setting

Check configuration


<?
phpinfo();
?>

PHP register_global = On/Off

Install PHP (With IIS)

1. register_global = On You can get variable by html element name or method.

Example

<input type="text" name="txtName">

Get variable


<?
echo $txtName;
//or
echo $_POST["txtName"];
?>

Install PHP (With IIS)

2. register_global = Off You can get variable by html element name and method.

Example get variable method post

<form name="frmMain" action="" method=”post”>
<input type=
"text" name="txtName">
</form>

Get variable


<?
echo $_POST["txtName"];
?>

Example get variable method get

<form name="frmMain" action="" method=”get”>
<input type=
"text" name="txtName">
</form>

Get variable


<?
echo $_GET["txtName"];
?>

or get variable from QueryString

http://localhost/index.php?sitename=shotdev.com


<?
echo $_GET["sitename"];
?>

Install PHP (With IIS)

3. Change configuration regsiter_global setting.

Click  Start -> Run -> php.ini or open C:\Windows\php.ini

php.ini

and restart apache web server
Install PHP (With IIS)

4. Get variable in both type On/Off


<?
//*** Register Global =On/Off Function ***//
$phpVersion = phpversion();
list($v_Upper,$v_Major,$v_Minor) = explode(".",$phpVersion);

if (($v_Upper == 4 && $v_Major < 1) || $v_Upper < 4) {
$_FILES = $HTTP_POST_FILES;
$_ENV = $HTTP_ENV_VARS;
$_GET = $HTTP_GET_VARS;
$_POST = $HTTP_POST_VARS;
$_COOKIE = $HTTP_COOKIE_VARS;
$_SERVER = $HTTP_SERVER_VARS;
$_SESSION = $HTTP_SESSION_VARS;
$_FILES = $HTTP_POST_FILES;
}

if (!ini_get('register_globals')) {
while(list($key,$value)=each($_FILES)) $GLOBALS[$key]=$value;
while(list($key,$value)=each($_ENV)) $GLOBALS[$key]=$value;
while(list($key,$value)=each($_GET)) $GLOBALS[$key]=$value;
while(list($key,$value)=each($_POST)) $GLOBALS[$key]=$value;
while(list($key,$value)=each($_COOKIE)) $GLOBALS[$key]=$value;
while(list($key,$value)=each($_SERVER)) $GLOBALS[$key]=$value;
while(list($key,$value)=@each($_SESSION)) $GLOBALS[$key]=$value;
foreach($_FILES as $key => $value){
$GLOBALS[$key]=$_FILES[$key]['tmp_name'];
foreach($value as $ext => $value2){
$key2 = $key."_".$ext;
$GLOBALS[$key2]=$value2;
}
}
}
?>

Add this code Before read variable.

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.