<?php // 写入 // time()+3600指的是该cookie的生存周期,秒为位,1个小时(60秒*60分钟) setcookie("usercode", "9001", time()+3600); // 读取 echo $_COOKIE["usercode"]; echo "<br/>"; if (isset($_COOKIE["usercode"])) echo "Welcome " . $_COOKIE["usercode"] . "<br/>"; else echo "Welcome guest!<br />"; ?>