COOKIE时间设置的项目实例子 COOKIE时间设置的项目实例子 要代码哦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用COOKIE限制用户访问网站的时间 http://www.phpzc.com/read.php?tid-681-fpage-2.html这上面是分了两个文件 以前看到过 希望是你要的//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"); } ?>//study.php文件<?phpsession_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\">";}?> bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )setcookie() 定义一个和其余的 HTTP 标头一起发送的 cookie。和其它标头一样,cookie 必须在脚本的任何其它输出之前发送(这是协议限制)。这需要将本函数的调用放到任何输出之前,包括 <html> 和 <head> 标签以及任何空格。如果在调用 setcookie() 之前有任何输出,本函数将失败并返回 FALSE。如果 setcookie() 函数成功运行,将返回 TRUE。这并不说明用户是否接受了 cookie。 表格 1. setcookie() 参数详解参数 说明 举例 name Cookie 的名字。 使用 $_COOKIE['cookiename'] 调用名为 cookiename 的 cookie。 value Cookie 的值。此值保存在客户端,不要用来保存敏感数据。 假定 name 是 'cookiename',可以通过 $_COOKIE['cookiename'] 取得其值。 expire Cookie 过期的时间。这是个 Unix 时间戳,即从 Unix 纪元开始的秒数。换而言之,通常用 time() 函数再加上秒数来设定 cookie 的失效期。或者用 mktime()来实现。 time()+60*60*24*30 将设定 cookie 30 天后失效。如果未设定,cookie 将会在会话结束后(一般是浏览器关闭)失效。 path Cookie 在服务器端的有效路径。 如果该参数设为 '/' 的话,cookie 就在整个 domain 内有效,如果设为 '/foo/',cookie 就只在 domain 下的 /foo/ 目录及其子目录内有效,例如 /foo/bar/。默认值为设定 cookie 的当前目录。 domain 该 cookie 有效的域名。 要使 cookie 能在如 example.com 域名下的所有子域都有效的话,该参数应该设为 '.example.com'。虽然 . 并不必须的,但加上它会兼容更多的浏览器。如果该参数设为 www.example.com 的话,就只在 www 子域内有效。细节见 Cookie 规范中的 tail matching。 secure 指明 cookie 是否仅通过安全的 HTTPS 连接传送。当设成 TRUE 时,cookie 仅在安全的连接中被设置。默认值为 FALSE。 0 或 1 例子 1. setcookie() 发送例子$value = 'something from somewhere';setcookie("TestCookie", $value);setcookie("TestCookie", $value,time()+3600); /* expire in 1 hour */setcookie("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1); 以上資料來源於手冊 php字符串转换问题 连接点击弹出代码 关于PHP使用数据库问题 求一个插件!!!! 请问同样是没有接收到值,为什么一句是对的,一句是错的 请问怎么提取这个子串,才鸟 phpmyadmin 访问被拒绝 需要如何修改? 求助 !!!!!!! 有谁知道有支持双字节的小型PHP-IDE吗? 急急!!!!这样写sql有问题吗?请指教!! ODBC查询结果中,怎样移动记录指针?? AJAX中文乱码PHP完美解决(IE和Firefox兼容) Data truncated for column 'spending' at row 1
http://www.phpzc.com/read.php?tid-681-fpage-2.html
这上面是分了两个文件 以前看到过 希望是你要的
//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");
}
?>//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\">";
}
?>
setcookie() 定义一个和其余的 HTTP 标头一起发送的 cookie。和其它标头一样,cookie 必须在脚本的任何其它输出之前发送(这是协议限制)。这需要将本函数的调用放到任何输出之前,包括 <html> 和 <head> 标签以及任何空格。如果在调用 setcookie() 之前有任何输出,本函数将失败并返回 FALSE。如果 setcookie() 函数成功运行,将返回 TRUE。这并不说明用户是否接受了 cookie。 表格 1. setcookie() 参数详解参数 说明 举例
name Cookie 的名字。 使用 $_COOKIE['cookiename'] 调用名为 cookiename 的 cookie。
value Cookie 的值。此值保存在客户端,不要用来保存敏感数据。 假定 name 是 'cookiename',可以通过 $_COOKIE['cookiename'] 取得其值。
expire Cookie 过期的时间。这是个 Unix 时间戳,即从 Unix 纪元开始的秒数。换而言之,通常用 time() 函数再加上秒数来设定 cookie 的失效期。或者用 mktime()来实现。 time()+60*60*24*30 将设定 cookie 30 天后失效。如果未设定,cookie 将会在会话结束后(一般是浏览器关闭)失效。
path Cookie 在服务器端的有效路径。 如果该参数设为 '/' 的话,cookie 就在整个 domain 内有效,如果设为 '/foo/',cookie 就只在 domain 下的 /foo/ 目录及其子目录内有效,例如 /foo/bar/。默认值为设定 cookie 的当前目录。
domain 该 cookie 有效的域名。 要使 cookie 能在如 example.com 域名下的所有子域都有效的话,该参数应该设为 '.example.com'。虽然 . 并不必须的,但加上它会兼容更多的浏览器。如果该参数设为 www.example.com 的话,就只在 www 子域内有效。细节见 Cookie 规范中的 tail matching。
secure 指明 cookie 是否仅通过安全的 HTTPS 连接传送。当设成 TRUE 时,cookie 仅在安全的连接中被设置。默认值为 FALSE。 0 或 1 例子 1. setcookie() 发送例子$value = 'something from somewhere';setcookie("TestCookie", $value);
setcookie("TestCookie", $value,time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1); 以上資料來源於手冊