Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to set cookie expire time in php

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);
                     
                     
Source by www.php.net #
 
PREVIOUS NEXT
Tagged: #set #cookie #expire #time #php
ADD COMMENT
Topic
Name
3+3 =