跨用户的 PHP 会话范围
我一直在尝试做如下的事情。
JavaScript
$.ajax({
url: 'login.php',
type: 'GET',
success: function(response) {
// get token and store in cookie for further requests to other files
}
});
Login.php
<?php
// getting $user_id from database again user email and password
$user_id = "12345";
$_SESSION["user"] = $user_id;
echo $user_id;
?>
现在,由于多个用户将使用该应用程序并调用相同的 login.php 并传递他们的电子邮件和密码,我想向他们返回他们的 ID,他们可以使用该 ID 来访问其他资源。我有兴趣知道 PHP 会话对于所有用户是否会有所不同,或者如果 2 个或 2 个以上用户同时登录,同一用户是否会被覆盖?我不确定 PHP 会话范围。
I have been trying to do something like below.
JavaScript
$.ajax({
url: 'login.php',
type: 'GET',
success: function(response) {
// get token and store in cookie for further requests to other files
}
});
Login.php
<?php
// getting $user_id from database again user email and password
$user_id = "12345";
$_SESSION["user"] = $user_id;
echo $user_id;
?>
Now as multiple users would be using the app and calling the same login.php passing their email and password, I want to return them their id which they can use to access other resources. I am interested to know if PHP sessions would be different for all users or the same user would overwritten if 2 or more than 2 users login at the same time? I am not sure about PHP session scope.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们每个人都会有自己独特的会议。请确保您还首先在 login.php 中调用 session_start()
They would each have their own unique session. Please make sure you also call session_start() first in your login.php