没有设置cookie也会导致我的会话失败

I use this code to unset my cookies (thanks to Stack)

if (isset($_SERVER['HTTP_COOKIE'])) {
    $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
    foreach($cookies as $cookie) {
        $parts = explode('=', $cookie);
        $name = trim($parts[0]);
        setcookie($name, '', time()-1000);
        setcookie($name, '', time()-1000, '/');
    }

but this also unset my $_SESSION. How can that be?

dude session also stored as a cookie value which ends on the termination of the page or browser..

instead of unsetting every cookie be selective

(ie)

if you want to delete cookie named user

setcookie("user", "", time()-3600); //deletes only that cookie

you can see what are the cookies set using the print_r($_COOKIE); function...

Session generates session cookie for browser. That is basically the key against which session data is store on server in a file with the same name..

Thats how browser remember session..There are two methods to propagate a session id: 1.Cookies 2.URL parameter

If you don't want cookie.. you can pass session id in Url and can set name and parameter in PHP.ini

This is because sessions work by storing a session id on the users computer, then using this id to identify the user and find there related sission data that is stored on the server.

see here :http://www.lassosoft.com/Tutorial-Understanding-Cookies-and-Sessions

I think you are deleting the session id when you delete the cookies. Try and identify the session id when you are looping through the cookies and set an if ststement to miss the session out from being deleted.