$_POST is invisible !!

$_POST is invisible !!

Posted by: southof40
Posted on: 2008-02-07 01:07:00

Hi - I've got a DH hosted site for which all POST variables seem to have disappeared. I've written a test script to demonstrate this. Two forms - one submits using GET the other using POST. The GET one displays the variables and the to other doesn't. Can anyone see anything in the test script which would cause this to happen ? I'd be grateful for any advice.

<?php
error_reporting(E_ALL);
?>
<html>
<style>
body {
margin: 5%;
background-color: silver;
color: black;
font-family: verdana; arial; sans-serif;
font-size: 0.8em;
}
</style>
<body>
<h2> A Form using POST</h2>
<p>Press the button to see your form entries echoed to the screen in the 'POST Variables Dump'</p>
<form id="Form1" name="Form1" method="POST" action="<?php print $PHP_SELF; ?>">
<input type="checkbox" value="1" name="a1">
<input type="checkbox" value="1" name="b1">
<input type="submit" name="Answer" value="Submit this form using POST">
</form>
<h2> A Form using GET</h2>
<p>Press the button to see your form entries echoed to the screen in the 'GET Variables Dump'</p>
<form id="Form2" name="Form2" method="GET" action="<?php print $PHP_SELF; ?>">
<input type="checkbox" value="1" name="a2">
<input type="checkbox" value="1" name="b2">
<input type="submit" name="Answer" value="Submit this form using GET">
</form>
<?php
// ------------------------------------
print '<h2>POST Variables Dump</h2>';
print '$_POST array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
foreach ( $_POST as $key => $value ) {
print $key . " " . "=" . " " . $value;
print "<BR/>";
}
// ------------------------------------
print "<BR/>";
// ------------------------------------
print "<BR/>";
// ------------------------------------
print '<h2>GET Variables Dump</h2>';
print '$_GET array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
foreach ( $_GET as $key => $value ) {
print $key . " " . "=" . " " . $value;
print "<BR/>";
}
// ------------------------------------
print "<BR/>";
// ------------------------------------
print "<BR/>";
// ------------------------------------
print '$_REQUEST array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
foreach ( $_REQUEST as $key => $value ) {
print $key . " " . "=" . " " . $value;
print "<BR/>";
}
// ------------------------------------
// ------------------------------------
print "<BR/>";
// ------------------------------------
print "<BR/>";
// ------------------------------------
print '$_GLOBALS array';
// ------------------------------------
print "<BR/>";
// ------------------------------------
echo "<pre>"; print_r($GLOBALS); echo "</pre>";
?>

<?php
print $_POST['$a1'];
print $_POST['$b1'];
print $_GET['$a2'];
print $_GET['$b2'];
?>
</body>
</html>



Re: $_POST is invisible !!

Posted by: jgoldstick
Posted on: 2008-02-07 04:27:00

$SERVER[PHP_SELF]

Re: $_POST is invisible !!

Posted by: scjessey
Posted on: 2008-02-07 06:08:00

Actually, it should be:

$_SERVER['PHP_SELF']

-- si-blog --

Re: $_POST is invisible !!

Posted by: phphelp
Posted on: 2008-02-07 06:38:00

I am having the same problems too. All the _POST variables are blank. I had to pull down all my sites.

did they change the post_variable value?

Re: $_POST is invisible !!

Posted by: patricktan
Posted on: 2008-02-09 01:47:00

I did a test on $_POST. It is working properly.

Re: $_POST is invisible !!

Posted by: theraven
Posted on: 2008-02-09 03:06:00

If the action attribute is left blank, HTML defaults it to the current file, so the method for accessing PHP_SELF is irrelevant. Besides, that was not the problem. The form was being submitted as expected, the data is/was not being returned as expected.

Edit: It's not as irrelevant as I thought. After some testing, I have determined that, yes, you need to replace $PHP_SELF with $_SERVER['PHP_SELF']. PHP5 has register_globals off which eliminates all shortcut server variables (aka Magic Globals or Super Globals).

Source: http://us3.php.net/manual/en/language.variables.predefined.php

Visit me, please...
www.theraven7.comEdited by theraven on 02/09/08 03:23 AM (server time).

Re: $_POST is invisible !!

Posted by: scjessey
Posted on: 2008-02-09 07:23:00

In reply to:

I have determined that, yes, you need to replace $PHP_SELF with $_SERVER['PHP_SELF'].


I think you'll find I already said that above.

-- si-blog --

Re: $_POST is invisible !!

Posted by: theraven
Posted on: 2008-02-09 22:25:00

I know, but it can never be said enough. :)

Visit me, please...
www.theraven7.com

Re: $_POST is invisible !!

Posted by: southof40
Posted on: 2008-02-10 20:17:00

I got an email from DH tech support. It seems that someone screwed up the config on a bunch of machines which had the effect of removing the POST variables from all requests to those machines. It was fixed by the time I woke up.

Tags: test scriptdhvariablestest scriptdhvariables