$_POST 变量保持活动状态多长时间,PHP 如何决定 post 数组中的内容


How long do $_POST variables stay active, and how does PHP decide what goes in the post array?

假设我正在构建一个连接并基本上解析另一个网站的Web应用程序。 我的问题是,如果您使用具有多个变量的 PHP 脚本发布(假设通过速记$.post使用 jQuery/Ajax(。以这个脚本为例:

$user = $_POST['user'];
$pass = $_POST['pass'];
if(isset($user) && $user !== null){
   if(isset($pass) && $pass !== null)
    echo 'true'
   else
    echo 'false';
}

现在我们的应用程序真的很奇怪(只是一个示例(,并决定通过jQuery的$.post,以不同的时间间隔将用户和密码提交给脚本,这基本上将以ajax速记提交到脚本并检索数据。我们的应用程序将提交用户首先输入的用户名,但只是为了激怒用户,在单独的帖子调用中,它会在五分钟后提交密码。

所以以视觉方式

$.post('script.php',{user: 'username'}) -> posts to the script, but doesn't
return anything, as in this case it would return false
<em>5 minutes later</em>
$.post('script.php',{pass: 'password'}, function(data){
       alert("data returned: " + data);
});

如果它都来自同一页面,脚本会记住传递的上一个用户名 post 变量吗? 或者它会忘记它并且根本不运行(因为用户名未设置(?

基本上我的总体问题是,您能否在不同时间从同一页面向 PHP 脚本提交不同的 POST 变量,它们是否会在脚本中协同工作?

No.$_POST数组的上下文随着每个请求而变化,因为它将始终包含最后一个 POST 键值对。您可能正在寻求一种保留状态的机制,例如 $_SESSION 数组,当然您需要初始化并将值传递给自己。