[英]How can I get and print correctly a session in php?
I have this php that start a session if $msj
is "si" : 我有这个php如果
$msj
是“ si”则开始一个会话:
<?php
require "dao/daoLoginUsu.php";
class LoginUsuario{
public function setDatos($aInput) {
$obj = json_decode($aInput, true);
$Dao = new daoLoginUsuario();
$Dao->setDataDato($obj);
$msj = $Dao->setDataDato($obj);
if($msj == 'si'){
session_start();
$_SESSION['msj'] = 'si';
}
return $msj;
}
}
?>
And in this php I want print the session : 在这个php中,我想打印会话:
<?php
session_cache_limiter(false);
session_start();
print_r($_SESSION);
and then.. 接着..
if($_SESSION['msj'] == 'si'){.....
but when is "si" print_r($_SESSION);
但是什么时候是“ si”
print_r($_SESSION);
print: 打印:
Array
(
[slim.flash] => Array
(
)
)
Why I can't print the session? 为什么我无法打印会议?
The $_SESSION is just a global array in PHP, so like any array, it can be outputted using var_dump()
. $ _SESSION只是PHP中的全局数组,因此像任何数组一样,可以使用
var_dump()
输出。 Some formatting makes the output more readable. 某些格式可使输出更具可读性。
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
Be sure to call session_start() at the top of all the pages that use the session in your program. 确保在程序中使用该会话的所有页面的顶部调用session_start()。
http://php.net/manual/en/function.session-start.php http://php.net/manual/zh/function.session-start.php
<?php
session_start();
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
?>
Try this: 尝试这个:
<?php
session_start();
echo $_SESSION['msj'];
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.