Unsetting a $_SESSION with references

26 Views Asked by At

I am trying to unset a session from $_SESSION with the following function:

public function unsetSession($s) {

        if (is_array($s)) {
    
            $temp = &$_SESSION;
                            
            foreach ($s as $value) {

                if (isset($temp[$value])) {

                    $temp = &$temp[$value];

                }
                else {

                    return false;

                }
                
            }

            unset($temp);

            return true;

        }

}

I call it like this unsetSession(array("key1", "key2", "etc."));.

However, it doesn't work and the session will not be deleted. What am I missing?

Thank you in advance!

0

There are 0 best solutions below