1

A certain PHP page I have cannot read POSTed values. I have already read (and tried) suggestions from the following stack posts:

PHP Can't get post data

Can't get $_POST values (php, html)

Can't get the $_POST Variable

PHP $_POST not working?

PHP POST not working

I can't read my POST HTTP request's body with PHP !

I can prove that the posted values are coming from the sending PHP page. From the Network tab of Chrome dev tools:

enter image description here

Here is my code:

$firstName = trim($_POST["txtFirstName"]);
$lastName = trim($_POST["txtLastName"]);
$email = trim($_POST["txtEmail"]);
$phone = trim($_POST["txtPhone"]);

var_dump( $_POST );
echo "<br>";
print_r($_POST);
echo "<br>";
print_r($_REQUEST);
echo "<br>";
echo("firstName: $firstName" . "<br>");
echo("lastName: $lastName" . "<br>");
echo("txtFirstName: " . $_POST["txtFirstName"] . "<br>");
echo("txtLastName: " . $_POST["txtLastName"] . "<br>");
die();

And the results sent to the browser:

array(0) { } 
Array ( ) 
Array ( ) 
firstName: 
lastName: 
txtFirstName: 
txtLastName: 

Here's a portion of the form from the submitting page:

<form method='post' action="Signup1.php" onsubmit="return checkForm(this)">
   ...
   <input name='txtFirstName' id='txtFirstName' maxlength="25" type='text' />
   ...
</form>

As you can see, everything is blank/empty. I have worked with PHP form posts many times over the years and never had a problem like this. I'm running PHP 5.6.11 locally on my IIS machine.

My php scripts are in the same folder tree shared by an asp.net app (in a configured IIS application). When I move my php scripts out of that tree, everything works fine. Why should that matter, and what is causing the problem?

Any ideas?

HerrimanCoder
  • 6,835
  • 24
  • 78
  • 158
  • 1
    What do [`php://input`](http://php.net/manual/en/wrappers.php.php) and [`$HTTP_RAW_POST_DATA`](http://php.net/manual/en/reserved.variables.httprawpostdata.php) indicate? – Boaz Dec 23 '17 at 22:45
  • Check your 2 maybes. – Funk Forty Niner Dec 23 '17 at 23:16
  • Can you try installing XAMPP? That would at least tell you if it's an IIS problem. –  Dec 23 '17 at 23:24
  • I discovered that my php scripts are in the same folder tree shared by an asp.net app. When I move my php scripts out of that tree, everything works fine. WTH?? – HerrimanCoder Dec 24 '17 at 01:15
  • HTTP_RAW_POST_DATA is empty. "Check your 2 maybes" makes no sense to me. XAMPP - no thanks, IIS works fine with php, except in this odd case, been using it for years with no problems. – HerrimanCoder Dec 24 '17 at 01:18

2 Answers2

0

Maybe there's a problem with url redirecting. Sometimes it might happen that server is redirecting your/route to your/route/ with trailing slash which causes emptying of $_POST, because of redirect.

Jozef Cipa
  • 2,133
  • 3
  • 15
  • 29
  • Jozef, I verified there is no redirect going on other than the original form post from sender page to receiver page. And the fact that this all works *outside* the asp.net application virdir suggests something else is going on. – HerrimanCoder Dec 25 '17 at 14:31
0

I had same problem and solved it by changing this:

<modules runAllManagedModulesForAllRequests="true">

to this:

<modules>

in the "web.config".