Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 美元邮政';值只能使用一次?_Php_Post - Fatal编程技术网

Php 美元邮政';值只能使用一次?

Php 美元邮政';值只能使用一次?,php,post,Php,Post,post data.php可以创建一个表单,将用户名发布到show post data.php post-data.php <form method="post" action="show-post-data.php"> user:<input type="text" name="user"></input> <input type="submit" name="submit" value="submit"> </form&g

post data.php
可以创建一个表单,将用户名发布到
show post data.php

post-data.php

<form method="post" action="show-post-data.php">
user:<input type="text" name="user"></input>
        <input type="submit" name="submit" value="submit">
</form>
1.在浏览器中单击
127.0.0.1/post data.php

2.输入
tom
并单击提交按钮。
3.在浏览器中单击
127.0.0.1/显示post data.php

我们得到的结果如下:

array(2) { ["user"]=> string(3) "tom" ["submit"]=> string(6) "submit" }
4.在浏览器中再次单击
127.0.0.1/显示post data.php

没有输出。
$\u POST
现在为空。

$\u POST'值只能使用一次?

这是因为HTTP协议是无状态的,这意味着您在请求中发送的信息只能用于该请求(除非您将其存储在服务器中)


当您在POST中发送信息时,该信息以变量
$\u POST
的形式到达服务器(到您的PHP代码),您可以在该请求中使用。在下一个页面加载中,除非再次发送新信息,否则该变量将为空。这是正确的行为。

$\u POST
值只能使用一次

,可以多次使用,但只能在发布页面中使用

如果将该值发布到特定URL,则在该时间内只能在该指定URL中访问发布的变量。不在其他URL中或其他时间

如果需要在其他节/页中使用,则必须保存该值,或者必须存储在会话或cookie中

if(isset($_POST) && count($_POST)) { 
  $_SESSION['post'] = $_POST; 
}
if(isset($_SESSION['post']) && count($_SESSION['post'])) { 
  $_POST = $_SESSION['post']; 
}

因为您的表单方法是post,如果您想多次获取,那么使用表单方法是get(您的数据显示在url中),您也可以使用SEE了解更多详细信息,请阅读本文
if(isset($_POST) && count($_POST)) { 
  $_SESSION['post'] = $_POST; 
}
if(isset($_SESSION['post']) && count($_SESSION['post'])) { 
  $_POST = $_SESSION['post']; 
}