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

I want to see the contents of the $ _SESSION array using the print_r ($ _ SESSION) command, but I only get the following output:

Array () 

What am I missing?

thanks

+4
source share
4 answers

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

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

 <?php session_start(); echo "<pre>"; print_r($_SESSION); echo "</pre>"; ?> 
+17
source

Note <?php session_start(); ?> <?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); ?> 

Exit

 Array ( [hello] => world ) 
+4
source

Most likely you are missing.

 session_start(); 
+2
source

It actually prints session variables, but you haven't set them yet, so the array returned by print_r ($ _ SESSION) is empty, try setting the variables first, and then printing them.

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

+1
source

Source: https://habr.com/ru/post/1314752/


All Articles