php 查看php会话变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5383270/
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
View php session variables
提问by EmmyS
Not sure if this belongs here or at webapps... please move if appropriate.
不确定这属于这里还是在 webapps ......如果合适,请移动。
I don't even know if such a thing is possible, but is there an extension or add-on for either Firefox or Chrome that would let me view all my PHP session variables the way there are extensions that let you view cookies?
我什至不知道这样的事情是否可能,但是是否有适用于 Firefox 或 Chrome 的扩展程序或附加组件,可以让我像查看 cookie 的扩展程序一样查看所有 PHP 会话变量?
回答by Pascal MARTIN
Cookies are available on the client-side, so they can be seen from the browser.
Cookie 在客户端可用,因此可以从浏览器中看到它们。
On the other hand, session data is stored on the server, and never sent to the client (except you write some code to do just that, of course).
另一方面,会话数据存储在服务器上,永远不会发送到客户端(当然,除非您编写一些代码来做到这一点)。
To dump the content of a variable, like $_SESSION
, you can use the var_dump()
function.
On a development server, you can install the Xdebugextension to enhance its output greatly (and lots of other debugging-related things, btw).
要转储变量的内容,例如$_SESSION
,您可以使用该var_dump()
函数。
在开发服务器上,您可以安装Xdebug扩展以极大地增强其输出(以及许多其他与调试相关的东西,顺便说一句)。
If you don't want to pollute the HTML of your page, you could install the FirePHPextension to FireBug, and use the corresponding PHP library to send data (like dump of variables)to it.
This would allow your variables, like $_SESSION
, to be displayed in firebug's console.
如果您不想污染页面的 HTML,您可以将FirePHP扩展安装到 FireBug,并使用相应的 PHP 库向其发送数据(如变量转储)。
这将允许您的变量(如 )$_SESSION
显示在 firebug 的控制台中。
回答by Nick
PHP session variables are stored on the server and are inaccessible to the client.
PHP 会话变量存储在服务器上,客户端无法访问。
回答by netcoder
No. Session data is server-side, while cookies are client-side. The session cookie contains the session identifier, which the server (i.e.: PHP) uses to retrieve the proper session data.
不是。会话数据是服务器端的,而 cookie 是客户端的。会话 cookie 包含会话标识符,服务器(即:PHP)使用它来检索正确的会话数据。
It is not possible to view session data without remote access to the server, or using a script (that resides on the server).
如果不远程访问服务器或使用脚本(驻留在服务器上),则无法查看会话数据。
This is why it is recommended to store "sensitive" information in session instead of cookies, because it cannot be consulted/altered easily.
这就是为什么建议在会话中存储“敏感”信息而不是 cookie 的原因,因为它不能被轻易查阅/更改。
回答by Marc B
No. Session variables are stored on the server. The only thing that would be visible in Firefox is the ID of the session, stored in the session cookie (e.g. PHP_SESS_ID=randomgarbage
).
否。会话变量存储在服务器上。在 Firefox 中唯一可见的是会话 ID,它存储在会话 cookie 中(例如PHP_SESS_ID=randomgarbage
)。
You'd have to explicitly write a script that would dump out the session variables, something as simple as:
您必须明确编写一个脚本来转储会话变量,就像这样简单:
dumpsession.php:
转储会话.php:
<pre>
<?php
var_dump($_SESSION);
回答by Cninroh
To acces something fro ma session you could use var_dump, I dont the browser due security restrictions. http://php.net/manual/en/function.var-dump.php
要访问 ma 会话中的某些内容,您可以使用 var_dump,由于安全限制,我不使用浏览器。 http://php.net/manual/en/function.var-dump.php
回答by Mihai Nedelcovici
You can use: Print_r ($_SESSION);
您可以使用: Print_r ($_SESSION);
回答by Louis
I had this simple script that shows the $_SESSION variables.
我有一个显示 $_SESSION 变量的简单脚本。
<?php
error_reporting(E_ALL);
session_start();
if (isset($_POST['session'])) {
$session = eval("return {$_POST['session']};");
if (is_array($session)) {
$_SESSION = $session;
header("Location: {$_SERVER['PHP_SELF']}?saved");
}
else {
header("Location: {$_SERVER['PHP_SELF']}?error");
}
}
$session = htmlentities(var_export($_SESSION, true));
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Session Variable Management</title>
<style>
textarea { font: 12px Consolas, Monaco, monospace; padding: 2px; border: 1px solid #444444; width: 99%; }
.saved, .error { border: 1px solid #509151; background: #DDF0DD; padding: 2px; }
.error { border-color: #915050; background: #F0DDDD; }
</style>
</head>
<body>
<h1>Session Variable Management</h1>
<?php if (isset($_GET['saved'])) { ?>
<p class="saved">The session was saved successfully.</p>
<?php } else if (isset($_GET['error'])) { ?>
<p class="error">The session variable did not parse correctly.</p>
<?php } ?>
<form method="post">
<textarea name="session" rows="<?php echo count(preg_split("/\n|\r/", $session)); ?>"><?php echo $session; ?></textarea>
<input type="submit" value="Update Session">
</form>
</body>
</html>
Install it on a test server, name it "sess.php" or something like that, and it shows the current session. DO NOT LEAVE IT ON A PRODUCTION SERVER !!!
将其安装在测试服务器上,将其命名为“sess.php”或类似名称,它会显示当前会话。不要把它留在生产服务器上!!!