Jump to content

[SOLVED] Can anybody explain why php behaves inconsistently?


litarena

Recommended Posts

Can anybody explain why php behaves inconsistently with the same script and BOTH with and without an (*identical*) config file?

 

And with the config variable cgi.fix_pathinfo=1

set (on both identical configs)

 

I have two php configurations initially neither has a php.ini config file. (then in one experiment I put the same config file on both)

 

(a) PHP Version 4.0.6 (FreeBSD) Apache/1.3.6

(b) PHP Version 5.3.0 (Centos)  Apache/2.0.63

On both webservers I'm running exactly the same php script with no changes.

On webserver (a) when input data is entered the form is immediately cleared

and nothing else happens. (This is clearly an error)

 

BUT, on webserver (b) [running exactly the same script] (neither webserver

has a php.ini config file) I enter my name "Dirty Harry"

 

                  and the webserver returns:

User Has submitted the form and entered this name : Dirty Harry

You can use the following form again to enter the new name.

[Question]

    Why does one webserver work properly and the other, (with the same

script,) does not?

 

 

========================================================================

script is below

========================================================================

<?php if(isset($_POST['submit'])) {

  $name = $_POST['name'];

    echo "User Has submitted the form and entered this name : <b>" . $name . "</b>";

    echo "<br>You can use the following form again to enter the new name.";

}

?>

<HTML>

<HEAD><title>Using PHP_SELF</title></HEAD>

<BODY>

<FORM name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

  Enter Your Name: <input type="text" name="name"><br>

  <input type="submit" name="submit" value="Submit Form"><br>

</FORM>

</BODY>

</HTML>

 

Link to comment
Share on other sites

(a) PHP Version 4.0.6 (FreeBSD) Apache/1.3.6

(b) PHP Version 5.3.0 (Centos)  Apache/2.0.63

 

Damn I need to get my eyes checked I didn't even see that at first. Upgrade server a to the version of server b and you are good to go. The reason your script on a is failing is due to the php version installed 4.0.6 $_SERVER as in $_SERVER['PHP_SELF'] was only introduced as of 4.1.0 pointed out by pfmabismad.

Link to comment
Share on other sites

Have you tried outputting what $_POST contains on both servers after submitting the form?

 

var_dump($_POST)

on the webserver which works returns

array(2) { ["name"]=>  string(10) "Dirty Harry" ["submit"]=>  string(11) "Submit Form" }

 

And on the webserver which doesn't work, the same script returns:

NULL

 

 

 

 

Link to comment
Share on other sites

error_reporting(E_ALL);

 

Warning: Undefined variable: _POST in /usr/local/apache/htdocs/HTML/PHP/PHP-tutorial/FormProcessing/self-tesstformgood.php on line 27

 

!!! Ha!

 

I wanted to find out specifically why it didn't work!

 

Now I know!

 

Thanks guys!

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.