一 代码
class="php"><?php
date_default_timezone_set("PRC"); //使用中华人民共和国的时区
if(!isset($_COOKIE["visit_time"])){ //如果Cookie文件是否存在,如果不存在
setcookie("visit_time",date("Y-m-d H:i:s")); //设置一个Cookie变量
$string="欢迎您第一次访问网站!"; //输出字符串
}else{ //如果Cookie存在
setcookie("visit_time",date("Y-m-d H:i:s"),time()+60); //设置带Cookie失效时间的变量
$string="您上次访问网站的时间为:".$_COOKIE["visit_time"]; //输出上次访问网站的时间
}
?>
<style type="text/css">
<!--
.STYLE1 {
font-family: "华文琥珀";
font-size: 24px;
color: #E45F00;
}
.STYLE2 {
font-family: "华文琥珀";
font-size: 18px;
color: #E45F00;
}
.STYLE3 {
font-weight: bold;
font-size: 18px;
font-family: "华文琥珀";
color: #F1EAE0;
}
-->
</style>
<table width="469" height="260" border="0" cellpadding="0" cellspacing="0" background="images/bg1.jpg">
<tr>
<td width="59" height="100"> </td>
<td width="253" align="center"><span class="STYLE1">读取Cookie变量</span></td>
<td width="157"> </td>
</tr>
<tr>
<td height="140"> </td>
<td align="center" valign="top" class="STYLE2"><?php echo $string; ?> </td>
<td align="center" class="STYLE3"><p> </p>
<p><?php echo date("Y-m-d"); //输出当前的访问时间?></p>
<p><?php echo date("H:i:s");?></p></td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
</tr>
</table>
?
? 二?运行结果 第一次运行:
