?? ??
?? ??
setcookie() ??? ?? PHP?? ??? ?????. ?? ??? ??? ????.
bool setcookie(??? ??[,??? ?[,int ??[, ??? ??[,??? ???[,int secure]]]]])
?? ??
PHP??? ?? ??? ?? $_COOKIE[]? ?? ???? ??? ?? ?? ?? ?? ? ????.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>PHP語(yǔ)言基礎(chǔ)</title> </head> <body> <?php date_default_timezone_set("PRC"); header("Content-Type:text/html; charset=gb2312"); if (!isset($_COOKIE["visittime"])) { setcookie("visittime", date("y-m-d H:i:s")); echo "這是第一次保存Cookie"."<br>"; } else { setcookie("visittime", date("y-m-d H:i:s"), time() + 60); echo "上次訪(fǎng)問(wèn)時(shí)間為:" . $_COOKIE["visittime"]; echo "<br>"; } echo "本次訪(fǎng)問(wèn)時(shí)間:" . date("y-m-d H:i:s"); ?> </body> </html>
? ?? ??:
?? ????? ?????
?? ??: 16-07-16 08:26:25
? ?? ?? ??:
??? ?? ??: 16-07-16 08:26:25
?? ?? ??: 16-07-16 08:27: 25
? ??? ?? isset() ??? ?? ?? ??? ??? ????, ?? ??? ??? setcookie() ??? ?? ?? ??? ????, ?? ?? ??? ?????. 60???.
?? ??
?? ?? ? ?? ??? ???? ??? ????? ?? ? ?? ??? ???? ?????. ????? ?? ?? ?? ??? ????? ? ?? ??? ????. ??? setcookie() ??? ???? ???? ???, ?? ??? ?????? ??? ???? ???? ????. ??? ??? ?????.
1. ??? ????? setcookie() ??? ?????.
?? ??? ????? ?? ??? ?????. setcookie() ??? ??? ???? ? ?????. ??? ????? setcookie() ??? ? ?? ????? null ??? ????, ? ?? ????? ??? ?? ??? ???? ?? ???? ?? ???? ???.
?? ?? ?? ?? ??? ?? ???? 1?? ? ???? ????? ??? ??? ????.
setcookie("name", "", time()-1) ;
? ???? time() ??? ?? ???? 1?? ?? ?? ?????? ????? ??? ?????.
2. ?????? ?? ?? ??
?? ?? ? ??? ???? ??? ??? ???? IE ????? Cookies ?? ??? ?????. ?????? ?? ??? ???? ?? ?? ??? ?????.
?? ?? ??
??? ??? ???? ?? ??? ?? ??? ???? ?? ????? ???? IE ????? ?? ?? ? ??? ???? ?????. . ??? ??? ??? ?? ???? ?? ????? ?? ???? ?? ???? ?????.
?? ??? ???? ????? ??? ?? ????? ????, ?? ??? ??? ??? IE ????? ?? ?? ??? ?? ?????.
??? ???? ????? ????? ??? ? ??? ????? ????. ????? ?? 300?? ?? ??? ??? ? ??? ? ?? ??? ?? 4KB? ????? ? ??? ??? ?? 20?? ??? ?????. ??? ???? ????? ???? ??? ?????.
? ????? ??? ???? ??? ??? ?? ????
??? ??????? ??? ???? ?? ????? ???? ?? ??, ??????? ? ????? ?? ???? ??? ????? ?? ??? ???? ???. ? ?? ??? ???? ???? ???? ????(? ????? ????? ??? ??? ??? ??????).
?? ??? ???? ?? ??? ??? ? "welcome.php"? ??? ??? ?????.
<html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html>
??? ?? "welcome.php"?? ?? ?????.
<html> <body> Welcome <?php echo $_POST["name"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old. </body> </html>