Getting PHP and Form variable in different operating system

Getting PHP and Form variable in different operating system

Windows code does not work in Linux,Unix. Similarly Linux code does not work in Windows and Unix. This can be achieved by the following method.

While running a PHP document in Windows we get the form variable by either GET or POST method. For which we use the following code:

$name=$_POST[”txtName”]; or $name=$_GET[”txtName”];

While using the same code in Linux and Unix we will get a error message. To solve this problem or to run a PHP page in a different operating system without any errors, first declare the GET variables and POST variables globally using the following code.

<?php

if (isset($HTTP_POST_VARS)){

while(list($name,$value)= each($HTTP_POST_VARS)){

$$name=$value ;

}

}

if (isset($HTTP_GET_VARS)){

while(list($name,$value)= each($HTTP_GET_VARS)){

$$name=$value ;

}

}

if (isset($HTTP_SERVER_VARS)){

while(list($name,$value)= each($HTTP_SERVER_VARS)){

$$name=$value ;

}

}

if (isset($_FILES)){

while(list($name,$value)= each($_FILES)){

$$name=$value ;

}

}

if (isset($_SERVER)){

while(list($name,$value)= each($_SERVER)){

$$name=$value ;

}

}

?>

We can use this code in every page or declare it in the common page and include the common page in every other PHP page.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.