merlinthemagic / MTS

Automation Tools for PHP
GNU Lesser General Public License v3.0
111 stars 29 forks source link

PHP Session destroy not working #29

Closed ShayanArifButt closed 7 years ago

ShayanArifButt commented 7 years ago

So i sometimes save the browser state in a session , and continue the automationtask from where i left by loading window obj etc from the session. But when i manually try to destroy the session , php does not destroy it. although i have noticed that when the actual folder from the work directory is destroyed ( eg ini_set('max_execution_time', 300); ) after for example 300 seconds , only then php lets me destroy the session function logout(){ session_start(); session_unset(); session_destroy(); header("Location: mts_add_address.php"); exit; }

if( isset($_REQUEST["logout"]) && $_REQUEST["logout"] == "yes" ){logout();}

eg saving in a PHP session, this will not get destroyed manually , only destroyed until the folder in work directory is destroyed ( this is what i have observed , i could be wrong ): $saveWindowObj = serialize($windowObj);
$_SESSION["window_obj"] = $saveWindowObj;

If the folder is still present in the WorkDirectory , and i try to destroy my session and after destroying it when i print the session variable ,
var_dump($_SESSION);

all my set session variables are still there.

ShayanArifButt commented 7 years ago

i solved session destroy issue using this function;

`function session_destroy_if_time_over($time){

if( time() - $_SESSION['time'] > $time ){   

            //session_start();  // Uncomment this if session_start() is not already set
    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (ini_get("session.use_cookies")) {
        $params = session_get_cookie_params();
        setcookie(session_name(), '', time() - 42000,
            $params["path"], $params["domain"],
            $params["secure"], $params["httponly"]
        );
    }

    // Finally, destroy the session.
    session_destroy();      
    $actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";       
    header('Location: '.$actual_link);
    exit;           
}
else{echo "session_destroy_if_time_over NOT true";return false;}

}`

merlinthemagic commented 7 years ago

great. closing.