ฟังก์ชั่น setcookie()
ความหมายของฟังก์ชั่นและการใช้งาน
การกำหนดค่าของคุ้กกี้ ด้วยฟังก์ชั่น setcookie()
รูปแบบการเขียน (Syntax)
- ตัวแปร name คือ กำหนดชื่อของคุ้กกี้
- ตัวแปร value คือ กำหนดค่าข้อมูลของคุ้กกี้
- ตัวแปร expire คือ กำหนดเวลาหมดอายุของคุ้กกี้ ( ถ้าไม่กำหนดจะคงอยู่ตลอด )
- ตัวแปร path คือ กำหนดพาธที่เก็บคุ้กกี้
- ตัวแปร domain คือ กำหนดโดเมนที่ใช้คุ้กกี้
bool setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] )
ตัวอย่างที่ 1
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
?>
ตัวอย่างที่ 2
<?php
// Print an individual cookie
echo $_COOKIE["TestCookie"];
// Another way to debug/test is to view all cookies
print_r($_COOKIE);
?>