When you start a session the PHPSESSID
will be added to the $_COOKIE
array, which you reset when setting the setcookie
using the foreach.
You can try this:
// Destroy all cookies.
foreach ( $_COOKIE as $key => $value ){
if($key != 'PHPSESSID'){
setcookie( $key, "", time()-1800, '/' );
}
}