Learning & Integrating web technology and code help directory

How to get variable with register_global = On/Off

No comments
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

  1. <?  
  2. phpinfo();  
  3. ?>  
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

  1. <?  
  2. echo $txtName;  
  3. //or  
  4. echo $_POST["txtName"];  
  5. ?>  
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

  1. <?  
  2. echo $_POST["txtName"];  
  3. ?>  
Example get variable method get
<form name="frmMain" action="" method=”get”>
<input type=
"text" name="txtName">
</form>
Get variable

  1. <?  
  2. echo $_GET["txtName"];  
  3. ?>  
or get variable from QueryString
http://localhost/index.php?sitename=shotdev.com

  1. <?  
  2. echo $_GET["sitename"];  
  3. ?>  

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

  1. <?  
  2. //*** Register Global =On/Off Function ***//  
  3. $phpVersion = phpversion();  
  4. list($v_Upper,$v_Major,$v_Minor) = explode(".",$phpVersion);  
  5.   
  6. if (($v_Upper == 4 && $v_Major < 1) || $v_Upper < 4) {  
  7. $_FILES = $HTTP_POST_FILES;  
  8. $_ENV = $HTTP_ENV_VARS;  
  9. $_GET = $HTTP_GET_VARS;  
  10. $_POST = $HTTP_POST_VARS;  
  11. $_COOKIE = $HTTP_COOKIE_VARS;  
  12. $_SERVER = $HTTP_SERVER_VARS;  
  13. $_SESSION = $HTTP_SESSION_VARS;  
  14. $_FILES = $HTTP_POST_FILES;  
  15. }  
  16.   
  17. if (!ini_get('register_globals')) {  
  18. while(list($key,$value)=each($_FILES)) $GLOBALS[$key]=$value;  
  19. while(list($key,$value)=each($_ENV)) $GLOBALS[$key]=$value;  
  20. while(list($key,$value)=each($_GET)) $GLOBALS[$key]=$value;  
  21. while(list($key,$value)=each($_POST)) $GLOBALS[$key]=$value;  
  22. while(list($key,$value)=each($_COOKIE)) $GLOBALS[$key]=$value;  
  23. while(list($key,$value)=each($_SERVER)) $GLOBALS[$key]=$value;  
  24. while(list($key,$value)=@each($_SESSION)) $GLOBALS[$key]=$value;  
  25. foreach($_FILES as $key => $value){  
  26. $GLOBALS[$key]=$_FILES[$key]['tmp_name'];  
  27. foreach($value as $ext => $value2){  
  28. $key2 = $key."_".$ext;  
  29. $GLOBALS[$key2]=$value2;  
  30. }  
  31. }  
  32. }  
  33. ?>  
Add this code Before read variable.

No comments :

Post a Comment