php://input和parse_str()使用

php://input可以读取没有处理过的POST数据,总结起来就是,

在用$_POST获取不到由APP或者一些接口的回调数据时,就用php://input试试

实例

index.php

<form action="test.php" method="post">   
    <input type="text" name="username">   
    <input type="password" name="password">   
    <input type="submit">   
</form>

test.php
<?php
    header("Content-Type:text/html;charset=utf-8");
    $file_in = file_get_contents("php://input"); 
    echo $file_in;
    echo "<br>";
    echo urldecode($file_in);

结果 

username=张三$password=123456

username=张三$password=123456

<?php
parse_str($file_in,$myArray);
print_r($myArray);
?>

结果

Array ( [username] => 张三[password] => 123456)

原文地址:https://www.cnblogs.com/jiaoaozuoziji/p/9198738.html