结果果然是整个$_COOKIE数组都是空的,而非仅仅$_COOKIE["testcookie"]为空。于是用winsock抓包,观察返回的http头,发现http头竟然是“Set-Cookie: testcookie=deleted; expires=Mon, 18-Jun-2007 02:42:33 GMT”,这说明“setcookie("testcookie", "");”的的确确是将testcookie这个cookie直接删除,而关于这种情况在php手册中完全没有说明。 最后阅读php源码,终于发现真相(这就是开源的好处了,有什么不清楚的内幕,直接查源码)。 以下代码可以在php5.20的linux源码包中ext/standard/head.c第99行附近找到: 复制代码 代码如下: if (value && value_len == 0) { /* * MSIE doesn"t delete a cookie when you set it to a null value * so in order to force cookies to be deleted, even on MSIE, we * pick an expiry date 1 year and 1 second in the past */ time_t t = time(NULL) - 31536001; dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, t, 0 TSRMLS_CC); sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", name, dt); efree(dt); } else { sprintf(cookie, "Set-Cookie: %s=%s", name, value ? encoded_value : ""); if (expires > 0) { strcat(cookie, "; expires="); dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, expires, 0 TSRMLS_CC); strcat(cookie, dt); efree(dt); } }