📜  如何在php代码示例中设置cookie过期时间

📅  最后修改于: 2022-03-11 14:54:40.081000             🧑  作者: Mango

代码示例1
HOW TO SET COOKIES: (to store small pieces of data in CLIENTS browser)

DESCRIPTION:
setcookie(string $name, string $value = "", int $expires = 0 (no expiry) ): bool
                     
EXAMPLE:
$value = 'something from somewhere';

setcookie("TestCookie", $value); // default no expiry
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */

// Print an individual cookie value- $_COOKIE["Cookie Key Name"];
echo $_COOKIE["TestCookie"];

// View all cookies
print_r($_COOKIE);

                     
FULL PARAMETER OPTIONS:
setcookie(
    string $name,
    string $value = "",
    int $expires = 0,
    string $path = "",
    string $domain = "",
    bool $secure = false,
    bool $httponly = false
): bool
                     
EXAMPLE:
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);