Question

Why I am getting an empty array of the session when I am trying a var_dump in another page? In the server, the session is stored without any content, only with the name of the id. With cookies all works well. Sometimes (yes, sometimes), I restart the server, and then, the sessions works well too. What may cause this issue?

Maybe a bug of the php 5.1.6? or a problem in the config of the server?

index_2.php

<?php
session_start();
$_SESSION['xxx'] = "tessstsse";
var_dump($_SESSION);//here show the correct session
header( 'Location: index_3.php');

index_3.php

<?php
session_start();
var_dump($_SESSION);

The output of this will be:

array
  empty
Was it helpful?

Solution 2

I have the web server without space to store the session content.

0% of free space. Delete some data and the problem is solved.

OTHER TIPS

Give this a try.. if this works I'd re examine your code else it is probably an issue with your server...

page1.php

<?php
    session_start();
    $_SESSION['auth'] = "true";
    $_SESSION['superhero'] = "batman";
?>
<a href="page2.php">Click here</a>

page2.php

<?php
    session_start(); // start the session before using it
    //echo $_SESSION['auth']; // will output 'true'
    print_r($_SESSION); 
?>

destroy.php

<?php
    session_start(); // start the session before using it
    session_destroy(); // deletes the current session..
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top