Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Problem With $http_post_vars
kvarnerexpress
post Feb 21 2006, 01:49 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



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:
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?

Go to the top of the page
 
+Quote Post
Spectre
post Feb 21 2006, 01:55 PM
Post #2


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



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:

CODE
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?

CODE
    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>');
Go to the top of the page
 
+Quote Post
OpaQue
post Feb 21 2006, 06:57 PM
Post #3


Administrator
Group Icon

Group: Admin
Posts: 1,459
Joined: 11-June 04
From: Somewhere in Time & Space.
Member No.: 1



This piece of information might prove helpful..
QUOTE
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


Go to the top of the page
 
+Quote Post
adly3000
post Feb 22 2006, 03:07 PM
Post #4


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 31-January 06
Member No.: 17,937



i agree with OpaQue:
QUOTE
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:
CODE
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:
CODE

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


This post has been edited by adly3000: Feb 22 2006, 03:09 PM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Http Authentication Without Using The Popup(3)
  2. Compare Two Vars And Highlight The Differences(7)
  3. Flash + PHP: How can I transfer vars?(4)
  4. Http_redirect() [resolved](5)


 



- Lo-Fi Version Time is now: 5th September 2008 - 12:53 PM