haider
haider

Reputation: 39

Session Variables are not being set/destroyed

On my live server, I have a folder structure like this:

- index.php
- unset.php
- info.php
- deep/
-- index.php

The code in the index.php which I'm using to see if the session variable is set or not, is as follows:

<?php
    session_start();
    print session_id();
    print "dev <br>";
    echo '<pre>';
    print_r($_SESSION);
    echo '</pre>';
?>

The code in the deep/index.php which I am using to set the session variable is as follows:

<?php
    session_start();
    print session_id();
    $_SESSION['usr'] = "bro";
    echo '<pre>';
    print_r($_SESSION);
    echo '</pre>';
?>

And finally the unset.php file which unsets the session. The code in the file is:

<?php
    session_start();
    echo "<br>";
    echo session_id();
    echo "<br>";
    session_unset();
    session_destroy();
    header("Location:/");
?>

The Problem

If you go to http://test.haidrr.com You will see the /index.php file which shows an empty array because the session variable is yet to be set. Note the session_id() on the top. Now if you go to /deep, The index.php file there will set a Session Variable which will show up in the array. Alright now come back to / and if you're lucky, you will see the session varible in the array. (Which I don't see sometimes, Sometimes it works, sometimes it doesn't). Try to /unset.php the variable and the session variable is still there.

This example works perfectly on my localhost. I've also included a info.php file which has the phpinfo() function.

Upvotes: 1

Views: 123

Answers (2)

Haresh Vidja
Haresh Vidja

Reputation: 8496

I have faced same issue on server, but after see in cpanel memory was full.. I have remove some logs file and temporary files. session will works properly..

Please check memory of server and if it have not empty then please remove temporary files.

Upvotes: 0

Mohit Tanwani
Mohit Tanwani

Reputation: 6628

I think I can see the session set on following link.

http://test.haidrr.com/deep/

Could you please try with following to unset the session.

unset($_SESSION['usr']);
session_destroy();

Please let me know if you still find the problem

Upvotes: 1

Related Questions