index.php 如下:----------------------------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>使用COOKIE限制用户访问网站的时间</title>
<style type="text/css">
<!--
.style1 {font-size: 12px}
.style2 {
font-size: 18px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="392" height="179" border="1" cellpadding="2" cellspacing="1" bordercolor="#33CCFF" bgcolor="#FFCC00">
<tr>
<td height="179" align="center" valign="middle" bgcolor="#FFFFCC"><span class="style2">试用版学习资源网</span><br> <br> <table width="392" border="0" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="index_ok.php">
<tr bgcolor="#FFFFCC">
<td width="76" height="33"> </td>
<td width="63" align="center"><span class="style1">用户名</span>:</td>
<td width="129"><input name="user" type="text" id="user" size="15"></td>
<td width="55" align="center"><input type="submit" name="Submit" value="登录"></td>
<td width="69"> </td>
</tr>
<tr bgcolor="#FFFFCC">
<td height="27"> </td>
<td align="center"><span class="style1">密 码</span>:</td>
<td><input name="pass" type="password" id="pass" size="15"></td>
<td align="center"><input type="reset" name="Submit2" value="重填"></td>
<td> </td>
</tr>
</form>
<tr bgcolor="#FFFFCC">
<td height="34"> </td>
<td colspan="3" align="center">请购买正版,试用版仅能访问30秒种</td>
<td> </td>
</tr>
</table>
<div align="center"></div></td>
</tr>
</table>
</body>
</html>
index_ok.php 如下--------------------------------------------------------------------------------
<?php
setcookie("cookie1",$_POST[user],time()+30);
if($user!="" && $pass!=""){
header("location:study.php");
} else {
echo "user 和 pass 都是空";
}
?>
study.php 如下-----------------------------------------------------------------
<?php
session_start();
if($_COOKIE['cookie1']!=''){
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="refresh" content="10;url=study.php">
<title>使用COOKIE限制用户访问网站的时间</title>
<style type="text/css">
<!--
.style1 {
font-size: 25px;
font-family: "华文行楷";
}
-->
</style></head>
<body>
<table width="392" height="178" border="1" cellpadding="0" cellspacing="0" bgcolor="#FFFFCC">
<tr>
<td height="176" align="center">
<span class="style1">
<p>用户您好</p></span> <p> 您当前使用的是“试用版学习资源网”,主要应用COOKIE实现对网站访问时间的限制,当浏览者在网站中停留的时间超过网站规定的访问时间时,将自动跳转到登录页面,只有重新登录才可以继续访问 </p> <p class="style1"> </p></td>
</tr>
</table>
</body>
</html>
<?php
}else{
echo "您在本网站停留的时间已经超过我们限制的时间,系统将在5秒钟后退出登录!!谢谢!请稍等...";
echo "<meta http-equiv=\"Refresh\" content=\"5;url=index.php\">";
}
?>
--------------------------------------
运行结果:user 和 pass 都是空
-----------------------------------求大神解释 post 没有过去的原因