Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Problem With $http_post_vars

Recommended Posts

I have a piece of code on one server that works and the same piece of code on another server does not.
The difference is in the PHP verison & the Linux verison
The one that works runs PHP4 on Redhat Linux.
The one that doesn't runs PHP5 on SUSE Linux.
Not sure if this is where the issue lies or not. I do know that in one case I see an adrress in searchable and in the other case it is null.


PHP Code:

 if ($HTTP_POST_VARS[addr]) { 	$searchable = $HTTP_POST_VARS[addr]; 	echo "searchable = ".var_dump($searchable)."</br>"; 	$stack=array(); ...extra code } else { 	print("<form method=\"POST\" action=\"ifinfo-single.php\"><table><tr><td><b>Enter IP/range/list: </td><td><input type=\"text\" name=\"addr\"></td><td><input type=\"submit\" value=\"Submit\"></td></tr></table>"); 	print("<table><tr><td valign=top><b>Valid values: </td><td><font size=\"-1\"><ul><li>Single IP (172.16.32.152)</li><li>Range (172.16.32.140-144)</li><li>Semicolon seperated (172.16.32.140;172.16.32.151;172.16.32.152)</li></ul></td></tr></table>"); }  

Any ideas?

Share this post


Link to post
Share on other sites

I would suggest you use $_POST instead of $HTTP_POST_VARS. The former has superceded the latter - to the extent that I think some newer versions of PHP have alltogether dropped support for the previously used variable.

 

Also, I think it would probably a good idea to change the equivalent code above to:

 

if (isset($HTTP_POST_VARS['addr']) && $HTTP_POST_VARS['addr'] != '' ) { 	$searchable = $HTTP_POST_VARS['addr']; 	echo 'searchable = '.var_dump($searchable).'</br>'; 	$stack=array(); ...extra code }...

Remember to always enclose variable indexes (unless they are numeric) in quotes. $variable[index] may work on some systems, but $variable['index'] will work on all, and is a better standard of coding. Note that you should still replace $HTTP_POST_VARS with $_POST in the above block of code; I've just left it as is to make it easy to read.

 

Also, in the last section of your script, don't you think it would be easier to enclose the string in single quotes, and not have to escape every double quote you encounter?

 

print('<form method="POST" action="ifinfo-single.php"><table><tr><td><b>Enter IP/range/list: </td><td><input type="text" name="addr"></td><td><input type="submit" value="Submit"></td></tr></table>'); 	print('<table><tr><td valign=top><b>Valid values: </td><td><font size="-1"><ul><li>Single IP (172.16.32.152)</li><li>Range (172.16.32.140-144)</li><li>Semicolon seperated (172.16.32.140;172.16.32.151;172.16.32.152)</li></ul></td></tr></table>');

Share this post


Link to post
Share on other sites

This piece of information might prove helpful..

The deprecation of the old $HTTP_*_VARS arrays (which need to be indicated as global when used inside a function or method). The following autoglobal arrays were introduced in PHP ? 4.1.0. They are: $_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, $_REQUEST, and $_SESSION. The older $HTTP_*_VARS arrays, such as $HTTP_POST_VARS, still exist and have since PHP 3. As of PHP 5.0.0, the long PHP predefined variable arrays may be disabled with the register_long_arrays directive.

 

Also, external variables are no longer registered in the global scope by default. In other words, as of PHP ? 4.2.0 the PHP directive register_globals is off by default in php.ini

 

Share this post


Link to post
Share on other sites

i agree with OpaQue:

The deprecation of the old $HTTP_*_VARS arrays (which need to be indicated as global when used inside a function or method). The following autoglobal arrays were introduced in PHP ť 4.1.0. They are: $_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, $_REQUEST, and $_SESSION. The older $HTTP_*_VARS arrays, such as $HTTP_POST_VARS, still exist and have since PHP 3. As of PHP 5.0.0, the long PHP predefined variable arrays may be disabled with the register_long_arrays directive.

 

Also, external variables are no longer registered in the global scope by default. In other words, as of PHP ť 4.2.0 the PHP directive register_globals is off by default in php.ini

 

 

just cahnge the ($HTTP_*_VARS arrays i.e. $HTTP_POST_VARS) to ($_* i.e. $_POST)

 

i also agree with Spectre:

using isset in trhe if statement is better than just if:

if (isset($_POST['addr']) && $_POST['addr'] != '' ) { 	$searchable = $_POST['addr']; 	echo 'searchable = '.var_dump($searchable).'</br>'; 	$stack=array(); ...extra code }...

the above code better than the following one:

if ($_POST['addr']) { 	$searchable = $_POST['addr']; 	echo "searchable = ".var_dump($searchable)."</br>"; 	$stack=array(); ...extra code }

Edited by adly3000 (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.