--------------------------------------------------------------------------------
 函式:setcookie() 
--------------------------------------------------------------------------------
 
HTTP 相关函式库
setcookie
送出 Cookie 资讯到浏览器。语法: int setcookie(string name, string value, int expire, string path, string domain, int secure);传回值: 整数函式种类: 网路系统
 
 
内容说明 
本函式会跟着标头 Header 送出一段小资讯字串到浏览器。使用本函式要在送出 HTML 资料前,实际上 cookie 也算标头的一部份。本函式的参数除了第一个 name 之外,都是可以省略的。参数 name 表示 cookie 的名称;value 表示这个 cookie 的值,这个参数为空字串则表示取消浏览器中该 cookie 的资料;expire 表示该 cookie 的有效时间;path 为该 cookie 的相关路径;domain 表示 cookie 的网站;secure 则需在 https 的安全传输时才有效。想得到更多的 cookie 资讯可以到 http://www.netscape.com/newsref/std/cookie_spec.html,由 cookie 原创者 Netscape 所提供的完整资讯。
 
 
使用范例 
[email protected] (27-May-1999) 所提供的 setcookie() 及 header() 范例。<?php
$status = 0;
if (isset($myTstCky) && ($myTstCky == "ChocChip")) $status = 1;
if (!isset($CCHK)) {
  setcookie("myTstCky", "ChocChip");
  header("Location: $PHP_SELF?CCHK=1");
  exit;
}
?>
<html>
<head><title>Cookie Check</title></head>
<body bgcolor="#FFFFFF" text="#000000">
Cookie Check Status: 
<?php 
printf ('<font color="#%s">%s</font><br>;', 
  $status ? "00FF00" : "FF0000",
  $status ? "PASSED!" : "FAILED!"); 
?>
</body>
</html> --------------------------------------------------------------------------------