PHP sessions do not work at all

I tested php sessions with this feature

session_start(); $_SESSION['test'][] = time(); header('Content-type: text/plain'); print_r($_SESSION); 

In theory, it should return another element of the array every time I reload the page. But in my case, for some reason, it always displays a single element.

So I'm stuck, please help!

UPDATED

The PHP version on my server is 5.3.13. Here is what I have in the session section. enter image description here

+6
source share
3 answers

Workaround to try ...

 session_start(); if(isset($_SESSION['test'])){ array_push($_SESSION['test'], time());} else { $_SESSION['test']= time();} header('Content-type: text/plain'); print_r($_SESSION); 

If this does not work ... then you may not have cookies ...

+2
source

I tried your code ... its working fine

 <?php session_start(); $_SESSION['test'][] = time(); header('Content-type: text/plain'); print_r($_SESSION); ?> 

output :: Array ([test] => Array ([0] => 1370889004 [1] => 1370889023 [2] => 1370889024 [3] => 1370889025 [4] => 1370889025 [5] => 1370889025 [6 ] => 1370889025 [7] => 1370889026 [8] => 1370889026 [9] => 1370889026))

can you check if cookie is enabled or not?

0
source

Try as follows:

 session_start(); $_SESSION['test'][] = time(); header('Content-type: text/plain'); print_r($_SESSION); 
-3
source

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


All Articles