能否限制ip点击某个链接的次数??
问题描述:
比如
<a href="123.html"></a>,
这么个链接,每个访问的ip都只能点击3次,3次过后禁止点击,并弹框提示“你下载的很频繁”
用txt写入或者cookie的方式
php或者js
需要完整代码
答
在session里存入map,key是页面id,value是你的点击次数。
每次刷新+1
超过次数,跳转到错误页面
<?
session_start(); //开始使用session
if(!session_is_registered('count'))
{
session_register('count');
$count=1; //count变量为1
}
else
{
$count++;
if (count > 3) Header("Location:错误页面");
}
?>
<html>
...
答
还是需要服务器端控制才行,我一般用cookie 方式,就是记录这个页面有这个cookie点击过的。
要写个点击事件
cok("123.html",1)
function cok (name,value){//写入cookie
var Days = 1;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie (name){//读取cookie
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null)
return unescape(arr[2]);
return "";
}