PHP 个会话中发送的变量信息不正确

Incorrect variable information sent in PHP sessions

这是我目前拥有的:

PHP

$var1=$_GET['some_val1']
$var2=$_GET['some_val2']

$_SESSION["x"]=$var1;
$_SESSION["y"]=$var2;

header("Refresh: 180; http://some_ip/some_page.php");

这在单用户设置中效果很好。

但是如果我有多个用户同时发送值。 user2 发送的值在重定向后同时用于用户 1 和用户 2。

我不确定到底是什么导致了这个问题,因此框架有点模糊。我将举例说明:

**User 1**

$var1=$_GET['some_val1'] << hello
$var2=$_GET['some_val2'] << world

echo $var1, $var2 
hello world  << Correct
**User 2**

$var1=$_GET['some_val1'] << HI
$var2=$_GET['some_val2'] << ALL

echo $var1, $var2 
HI ALL  << Correct

**on some_page.php**

**USER 1**

echo $var1, $var2
HI ALL << incorrect 

**User 2**
echo $var1, $var2
HI ALL << correct 

为什么值没有在会话间正确发送 PHP 如何同时处理多个用户?

来自评论:

How do you define "different users"; are they different tabs on the same browser? different browsers on the same machine? Completely different devices?


Yes i am emulating different users by multiple tabs on my browser.


Sessions are stored in the browser, not the tab. If you want to test multiple users, either use different browsers (i.e. one in Chrome, one in Firefox), or test one in Privacy mode.

--艾因伯

是您出现不一致问题的原因。另外:

SESSIONS are stored until either unset or browser is exited. So if multiple users use the same browser without restarting it and you are not unsetting the SESSION variable once the required process is completed, you will face this issue. It is always a good practice to UNSET the SESSIONS once the process is completed.

-- 穆罕默德·阿赫塔尔·祖贝里