PHP ??
??
??? ? ???? ??? ? ?? ?? ??? ?? ??? ??????. ? ?????? ??? ??, ??, ??, ?? ?? ??? ??????. ?? ?? ?? ?? ???? ???? ?? ??
? ???? ???.
? ?? ?? ???? ??? ?? ??? ??? ??? ???? ?? ?? ?????. ? ??? ?? ?????.
??? ?? ???? ???? ? ?????. ??? ??? ???? ???? ???? ?? ?????. ??? ???? ????? ?? ???? ??? ??? ??? ???? ?????. PHP? ???? ?? ?? ???? ??? ? ????.
??? ??? ?????
setcookie()
??? ???? ??? ?????. ??: setcookie() ??? <html> ?? ?? ????? ???.
??
setcookie
(name,value,expire,path,domain)??? ?????. ??? ??? ?????. ?? ???????. ??? ?? ?????.
?? ????. ??? ?? ??? ?????.
??? ???????. ??? ?? ??? ?????.
???? ???????. ??? ??? ??? ?????.
? ??? ?? ????? ??? ?? ?????. setcookie(?? ??, ?? ?, ?? ?? ??), 3??? ?????.
??
?? ???? name ?? "user"? ?? "Alex Porter" ?? ?????. ?? ? ??? 1?? ?? ????? ?????. <?php
setcookie("user","Alex Porter",time()+3600);
?>
??: ??? ?? ? ?? ?? ???? URL ??????. , ?? ? ???? ??????(URL ???? ????? ?? setrawcookie() ??).
?? ?? ??? ?? ???? ??? ?? ????. ?? ?? ???? ??? ? ??? ? ????.
<?php $expire=time()+60*60*24*30; setcookie("user", "php", $expire); ?>? ????? ?? ??? 1??(60? * 60? * 24?? * 30?)? ???? ????.
Cookie? ?? ??? ?????
PHP? $_COOKIE ??? ?? ?? ???? ? ?????.
?? ???? "user"?? ??? ?? ???? ???? ?????.
<?php // 輸出 cookie 值 echo $_COOKIE["user"] ."<br/>"; // 查看所有 cookie print_r($_COOKIE); ?>
?? ?? php?? ??? ??? ?????? ???? ?? ??? ??? ????.
php
??? ??? ????. ( [pgv_pvi] => 9622684672 [???] => PHP )
?
?? ???? isset() ??? ???? ??? ?????? ?????:
<html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <?php header("Content-type:text/html;charset=utf-8"); if (isset($_COOKIE["user"])) echo "歡迎 " . $_COOKIE["user"] . "!<br>"; else echo "普通訪客!<br>"; ?> </body> </html>
???? ?? ??:
Welcome to php!
??? ???? ??? ??????
?? ?? ? ???? ?? ???? ???? ???.
?
"user"?? ???? "XX user"?? ?? ?????. ? ??? 1?? ?? ????? ???? ????:
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 setcookie("user","XX用戶",time()+3600); ?>
? ??? ????? ??? ?? ??? ?????.
<?php setcookie("user","",time()-3600); ?>
????? ?? ??? ???? ????. ??? ?? ????
??????? ??? ???? ?? ????? ???? ?? ?? ?? ??? ???? ??????? ??? ?? ??? ???? ???. ? ?? ??? ??? ?? ???? ???? ????(?? ? ??? ??? ? ????? ?? ??? ??????).
?
?? ??? ???? "??" ??? ???? "cookie_welcome.php"? ???? ?????. ?? :
<html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <form action="cookie_welcome.php" method="post"> 名字: <input type="text" name="name"> 年齡: <input type="text" name="age"> <input type="submit"> </form> </body> </html>??? ?? "cookie_welcome.php" ??? ?? ?????.
<?php header("Content-type:text/html;charset=utf-8"); echo "歡迎".$_POST['name'] ."<br>"; echo "你".$_POST['age'] ."歲了"; ?>???? ?? ??:
Welcome liuqi
You 23????