开发者

PHP, print_r($_SESSION) doesn't show its content?

I want to see the content of the the array $_SESSION with the command print_r($_SESSION) but what I get is just the following output:

Array ()

what am I miss开发者_运维技巧ing ?

thanks


Make sure you call session_start() at the top of all the pages you wish to use the session.

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

<?php

session_start();

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

?>


Note <?php session_start(); ?> must be called before any other output is sent to the browser.

index.php

<?php

session_start();
$_SESSION['hello'] = 'world';
print_r($_SESSION);

?>

Output

Array (
  [hello] => world
)


Most likely you are missing.

session_start();


Actually Its Printing The Session Variables But You Have Not Set Any Before Therefore The Array Returned By print_r($_SESSION) is Empty Try Setting The Variables First and Then Print Them.

Remember that session_start(); should always be first line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜