在php
中,我使用setcookie
来创建cookie,如docs所述,如果您未指定path
参数,则Cookie将在当前目录及其所有子目录。但我需要的cookie只能在当前目录中使用,而不能在其子目录中使用。我怎样才能做到这一点?如何在特定路径中但不在其子目录中使用`cookie`
//it is available in current directory and all of its sub-directories:
setcookie("TestCookie", $value);
//with the same effect:
setcookie("TestCookie", $value,/current-directory/);
我要排除/current-directory/*
非常感谢您
我不知道'setcookie()函数'函数内的溶液中。您可以简单地使用'$ _SERVER [“REQUEST_URI”]或$ _SERVER [“PHP_SELF”]'和一个正则表达式来检查当前脚本/ uri的路径,以使用或忽略该cookie。 –