PhpStorm $_POST always empty

痞子三分冷 提交于 2019-11-28 13:27:29

The new PhpStorm 2017.2.2 EAP build (172.3968.23) has solved this problem.

Bug WEB-17317 502 Bad Gateway error from the server when post data.

You can download it here.

Complete Release notes link=>confluence.jetbrains.com/display/PhpStorm/PhpStorm+EAP+172.3968.23+Release+Notes

Paste this workaround in your page's initialization to use $_POST as normal:

<?php
//required when using PhpStorm's built-in webserver
//which always makes $_POST empty
//and must have .ini setting always_populate_raw_post_data = -1
//but will NOT work with enctype="multipart/form-data"
$raw_str = file_get_contents('php://input'); //eg. name1=val&name2=val
if($raw_str) {
    foreach (explode('&', $raw_str) as $pair) {
        $keyvalue = explode("=", $pair);
        $key = urldecode($keyvalue[0]);
        $value = urldecode($keyvalue[1]);
        $_POST[$key] = $value;
    }
}
?>

It doesn't matter with PHPSTORM, HTTP_RAW_POST_DATA can store unrecognized data from request, have a try , content-type:application/x-www-form-urlencoded add to Http headers;

Try setting the enctype of the form, without it the $_POST array might not be populated as PHP only receives a string of fields without knowing what to do with it:

<form method='post' action='a.php' enctype="multipart/form-data">
    <input type='text' name='user_f'>
    <input type='submit' name='send' value='Send'>
</form>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!