php 如何使用会话 ID 获取会话变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8726268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:21:49  来源:igfitidea点击:

how to get session variables using session id

phpsession

提问by Manish Jangir

I have the session id of my application. now i want to get all the session variables by using this session id.

我有我的应用程序的会话 ID。现在我想通过使用这个会话 id 来获取所有的会话变量。

I used <?php echo session_id()?>to get the session id but how to get all the session object values by using this session id?

我曾经<?php echo session_id()?>获取会话 id 但如何通过使用此会话 id 获取所有会话对象值?

回答by Jeremy Harris

According to php.net: There are several ways to leak an existing session id to third parties. A leaked session id enables the third party to access all resources which are associated with a specific id. First, URLs carrying session ids. If you link to an external site, the URL including the session id might be stored in the external site's referrer logs. Second, a more active attacker might listen to your network traffic. If it is not encrypted, session ids will flow in plain text over the network. The solution here is to implement SSL on your server and make it mandatory for users.

根据php.net有几种方法可以将现有会话 ID 泄露给第三方。泄露的会话 ID 使第三方能够访问与特定 ID 相关联的所有资源。首先,带有会话 ID 的 URL。如果您链接到外部站点,则包含会话 ID 的 URL 可能会存储在外部站点的引荐来源日志中。其次,更活跃的攻击者可能会监听您的网络流量。如果未加密,会话 ID 将以纯文本形式通过网络传输。这里的解决方案是在您的服务器上实施 SSL 并强制用户使用。

This begs the question, how do you have the session ID but unable to access the script?

这就引出了一个问题,您如何拥有会话 ID 但无法访问脚本?

Regardless, you would need to set the session ID and then start it...then access the data.

无论如何,您需要设置会话 ID,然后启动它……然后访问数据。

session_id($whatever_id_you_have);
session_start();
echo $_SESSION['somekey'];

回答by Manish Jangir

You can check all session value using this one..

您可以使用此检查所有会话值..

print_r($_SESSION);

回答by KingCrunch

$_SESSIONis what you are looking for. Remember to call session_start()first. See http://php.net/session.examples.basic

$_SESSION就是你要找的。记得先打电话session_start()。见http://php.net/session.examples.basic

回答by Tatu Ulmanen

var_dump($_SESSION);will show you the contents of the current session, you can then access the values just like you would on a normal array.

var_dump($_SESSION);将显示当前会话的内容,然后您可以像访问普通数组一样访问这些值。