在 PHP 中跨服务器传输会话 [英] Transfer session across server in PHP

查看:44
本文介绍了在 PHP 中跨服务器传输会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要跨服务器传输用户会话.IE.如果用户登录 server1 并且用户存在于 server2 ,那么我必须将用户会话详细信息传输到 server2 .为此,我使用了以下技术

I need to transfer the user session across servers. ie. If user logged in server1 and if the user exists in server2 , then I have to transfer the user session details to server2. For this I used the following technique

从 server1,将用户重定向到 http://server2/auth_from_server1.php?sessionid=12345在 server2 上(内部,在 auth_from_server1.php 的 PHP 代码中),对 http://server1/secret/check_session_id.php 会话 ID 为 12345.在server1上,在check_session_id.php的实现中,验证ID并返回OK,FAILURE,以及你要传递的session相关数据,比如用户名,...在 server2 上,当调用返回 OK 时,存储传输的会话数据,并为用户提供此服务器的 cookie 和会话.

From server1, redirect user to http://server2/auth_from_server1.php?sessionid=12345 On server2 (internally, in the PHP code of auth_from_server1.php), do a request to http://server1/secret/check_session_id.php with the sessionid, 12345. On server1, in the implementation of check_session_id.php, validate the ID and return OK, FAILURE, and session related data you want to pass, such as username, ... On server2, when the call returns with OK, store the transferred session data, and give the user a cookie and session for this server.

但是当回调函数调用 auth_from_server1.php 时,session id 中的值为 null.我试图检查 sessionid 为

But when the call back function call the auth_from_server1.php the value in session id is null. I tryed to check the sessionid as

if(isset($_SESSION['sessionId']))
echo 'true';
else
echo 'false';

但是 $_SESSION['sessionId'] 为空.在登录页面中,我将会话 ID 的值设置为

But $_SESSION['sessionId'] is null. In login page I am setting the value for session id as

$_SESSION['sessionId'] = session_id();

提前致谢....

推荐答案

将会话数据存储在共享目录中会更容易吗?

Wouldnt it be easier to just store session data in a shared directory?

或者,您可以将其存储到数据库中.

Alternatively you can store it in a database.

这篇关于在 PHP 中跨服务器传输会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆