Posting from IE8 to PHP gives blank $_POST

我是研究僧i 提交于 2019-12-19 07:34:26

问题


I have a simple HTML form, sending a post request to a php script. In IE8, the form only works intermittently - most of the time the PHP script sees an empty $_POST variable.

Here's my code:

<html>
<head>
<title>Post test</title>
</head>
<body style="text-align: center;">
<?php

echo "<pre>".print_r($_POST, TRUE)."</pre>";

?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="name">
<input type="hidden" name="hidden" value="moo" >
<input type="submit" value="Search" >
</form>
</body>
</html>

Sometimes the print_r gives the response you'd expect (i.e. it's populated with the data from the form), most of the time it's empty.

Not being able to use POST is a bit of a problem for web applications - anyone got any ideas what's going on, and how to fix it?


回答1:


Thanks everyone for wading in on this one.

It turns out the problem lay in an Apache module I had enabled.

It's a module to allow apache to use Windows authentication to identify a user via their Windows User id - mod_auth_sspi

The effect is caused by a known bug, in the module, but with a simple extra directive this can be worked around, until a fix is added in the next update, as described here:

http://sourceforge.net/projects/mod-auth-sspi/forums/forum/550583/topic/3392037




回答2:


That sounds very very bizarre. Does it happen in other versions of IE as well?

I can't tell you what the problem is, but here are my suggestions on how to diagnose it:

  1. Print $_REQUEST rather than just $_POST, to see if the data is coming in via another method.

  2. Use a tool like Fiddler or Wireshark to track exactly what is actually being sent by the browser.

Fiddler in particular has been very helpful for me a few times (mainly when debugging Ajax code), and will tell you exactly what was posted by the browser. If your web server is localhost, you can also use Fiddler to track what is received before PHP gets its hands on it. If not, you can use wireshark on the server if you have permissions for installing that sort of thing.

In addition to Fiddler, I would have suggested a browser-based tool like Firebug, but I don't know of one for IE that is good enough (The IE dev toolbar doesn't give you details of request and response data, as far as I know).




回答3:


I'm suspicious that when the script is telling you that $_POST is empty, you did not actually POST the form. You can check by adding print($_SERVER['REQUEST_METHOD']); after your print_r($_POST);




回答4:


If you are posting a file some of the time (i.e. with a file input) then make sure you set enctype="multipart/form-data" in your <form> element.




回答5:


Have you checked the generated html? Is it possible that echo $_SERVER['PHP_SELF'] isn't producing the output you're after, which messes up the form html, which messes up the POST?



来源:https://stackoverflow.com/questions/4409847/posting-from-ie8-to-php-gives-blank-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!