简体   繁体   中英

How can I get and print correctly a session in php?

I have this php that start a session if $msj is "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

session_cache_limiter(false);
session_start();
print_r($_SESSION);

and then..

if($_SESSION['msj'] == 'si'){.....

but when is "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() . 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.

http://php.net/manual/en/function.session-start.php

<?php

 session_start();

 echo "<pre>";
 print_r($_SESSION);
 echo "</pre>";

?>

Try this:

<?php
session_start();
echo $_SESSION['msj'];
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM