限制页面刷新次数?

aabbabababaa 2016-12-02 02:10:57
index.php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<title>刮刮卡</title>
<link href="./css/activity-style.css" rel="stylesheet" type="text/css">
<?php include 'renew.php'; ?>
</head>



<script type="text/javascript">
function loading(canvas, options) {
this.canvas = canvas;
if (options) {
this.radius = options.radius || 12;
this.circleLineWidth = options.circleLineWidth || 4;
this.circleColor = options.circleColor || 'lightgray';
this.moveArcColor = options.moveArcColor || 'gray';
} else {
this.radius = 12;
this.circelLineWidth = 4;
this.circleColor = 'lightgray';
this.moveArcColor = 'gray';
}
}
loading.prototype = {
show: function() {
var canvas = this.canvas;
if (!canvas.getContext) return;
if (canvas.__loading) return;
canvas.__loading = this;
var ctx = canvas.getContext('2d');
var radius = this.radius;
var me = this;
var rotatorAngle = Math.PI * 1.5;
var step = Math.PI / 6;
canvas.loadingInterval = setInterval(function() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
var lineWidth = me.circleLineWidth;
var center = {
x: canvas.width / 2,
y: canvas.height / 2
};

ctx.beginPath();
ctx.lineWidth = lineWidth;
ctx.strokeStyle = me.circleColor;
ctx.arc(center.x, center.y + 20, radius, 0, Math.PI * 2);
ctx.closePath();
ctx.stroke();
//在圆圈上面画小圆
ctx.beginPath();
ctx.strokeStyle = me.moveArcColor;
ctx.arc(center.x, center.y + 20, radius, rotatorAngle, rotatorAngle + Math.PI * .45);
ctx.stroke();
rotatorAngle += step;

},
100);
},
hide: function() {
var canvas = this.canvas;
canvas.__loading = false;
if (canvas.loadingInterval) {
window.clearInterval(canvas.loadingInterval);
}
var ctx = canvas.getContext('2d');
if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height);
}
};
</script>

<body data-role="page" class="activity-scratch-card-winning">
<script src="./js/jquery.js" type="text/javascript"></script>
<script src="./js/wScratchPad.js" type="text/javascript"></script>
<div class="main">
<div class="cover">
<img src="./images/activity-scratch-card-bannerbg.png">
<div id="prize" action="renew.php" method="post" value="<?php echo $counts ?>">
</div>
<div id="scratchpad" action="renew.php" method="post" value="<?php echo $counts ?>">
</div>
</div>
<div class="content">
<div id="zjl" style="display:none" class="boxcontent boxwhite">
<div class="box">
<div class="" style="color: #444444;" align="center">
<span>
恭喜你!你中了:<span class="red" id ="theAward"></span>
</span>
</div>
<div class="Detail" align="center">
<p>卡号:<span class="red" id ="theAward1">

</span></p>

<p>密码:<span class="red" id ="theAward2">

</span>
<?php echo $cjkh1;?>
</p>
</div>

<div class="Detail">
<p>
<div align="center"><a href="http://www.test.com/yydb/"><img src="./images/qdj1.gif" alt="去兑奖" width="120" height="73" /></a>
</div>
</p>

</div>
</div>
</div>
<div class="boxcontent boxwhite">
<div class="box">
<div class="title-brown">
<span>
奖项设置:
</span>
</div>
<div class="Detail">

</div>
</div>
</div>
<div class="boxcontent boxwhite">
<div class="box">
<div class="title-green">
活动说明:
</div>
<div class="Detail">
<p class="red">
每天可以刮3次,你已经刮了<?php echo $counts ?>次,机会如果没用完,可刷新本页面再刮!
</p>
</div>
</div>
</div>

<div class="boxcontent boxwhite">
<div class="box">
<div class="title-red">
友情链接
</div>
<div class="Detail">
<p class="red">
<a href="http://www.test.com/blog/"><img src="./images/blog.gif" alt="blog.test.com" width="120" height="60" /></a>
<a href="http://www.test.com/bbs/"><img src="./images/bbs.gif" alt="bbs.test.com" width="120" height="60" /></a>
</p>
</div>
</div>
</div>


</div>
<div style="clear:both;">
</div>
</div>
<script src="./js/alert.js" type="text/javascript"></script>
<script type="text/javascript">

window.sncode = "null";
window.prize = "谢谢参与";

var zjl = false;
var num = 0;
var goon = true;
$(function() {
$("#scratchpad").wScratchPad({
width: 150,
height: 40,
color: "#a9a9a7",
scratchMove: function() {
num++;
if (num == 2) {
var randNum = Math.round(Math.random()*99+1)

if(randNum>=0 && randNum<=1){
var award = "一等奖";
zjl = true;

var cjkh = "<?php echo $rekh01['cjkh50']; ?>";
var cjkm = "<?php echo $rekh01['cjkm50']; ?>";

}
if(randNum>=2 && randNum<=10){
var award = "二等奖";
zjl = true;

var cjkh = "<?php echo $rekh01['cjkh10']; ?>";
var cjkm = "<?php echo $rekh01['cjkm10']; ?>";
}
if(randNum>=11 && randNum<=50){
var award = "三等奖";
zjl = true;

var cjkh = "<?php echo $rekh01['cjkh1']; ?>";
var cjkm = "<?php echo $rekh01['cjkm1']; ?>";

}

if(randNum>=51 && randNum<=100){
var award = "谢谢参与";
}
document.getElementById('prize').innerHTML = award;
$("#theAward").html(award);
document.getElementById('theAward1').innerHTML = cjkh;
$("#theAward1").html(cjkh);
document.getElementById('theAward2').innerHTML = cjkm;
$("#theAward2").html(cjkm);


}
if (zjl && num > 10 && goon) {

//$("#zjl").fadeIn();
goon = false;

$("#zjl").slideToggle(500);
//$("#outercont").slideUp(500)
}
}
});

//$("#prize").html("谢谢参与");
//loadingObj.hide();
//$(".loading-mask").remove();
});

$("#save-btn").bind("click", function() {
var btn = $(this);
var tel = $("#tel").val();
if (tel == '') {
alert("请输入手机号");
return
}

var submitData = {
tid: 438,
code: $("#sncode").text(),
tel: tel,
action: "setTel"
};
$.post('index.php?ac=acw', submitData,
function(data) {
if (data.success == true) {
alert(data.msg);
return
} else {}
},
"json")
});

// 保存数据
$("#save-btnn").bind("click", function() {
//var btn = $(this);
var submitData = {
tid: 438,
code: $("#sncode").text(),
parssword: $("#parssword").val(),
action: "setTel"
};
$.post('index.php?ac=acw', submitData,
function(data) {
if (data.success == true) {
alert(data.msg);
if (data.changed == true) {
window.location.href = location.href;
}
return
} else {}
},
"json")
});
</script>

</body>

</html>



renew.php

<!DOCTYPE html>
<html>
<head charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<title>¹ιο¨</title>
<link href="./css/activity-style.css" rel="stylesheet" type="text/css">

</head>
<body>
<?php
//empty($_SERVER['HTTP_VIA']) or exit("请不要用代理访问本站!");

//只能通过post方式访问
if ($_SERVER['REQUEST_METHOD'] == 'post')
{header('HTTP/1.1 404 Not Found'); die('亲,页面不存在');}
session_start();
$fs1=$_post['counts'];

//防刷新时间,单位为秒
$allowTime = 30;
$count=3;
//读取访客ip,以便于针对ip限制刷新
/*获取真实ip开始*/
if ( ! function_exists('GetIP'))
{
function GetIP()
{
static $ip = NULL;
if ($ip !== NULL)
{
return $ip;
}
if (isset($_SERVER))
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
/* 取X-Forwarded-For中第x个非unknown的有效IP字符? */
foreach ($arr as $xip)
{
$xip = trim($xip);
if ($xip != 'unknown')
{
$ip = $xip;
break;
}
}
}
elseif (isset($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
else
{
if (isset($_SERVER['REMOTE_ADDR']))
{
$ip = $_SERVER['REMOTE_ADDR'];
}
else
{
$ip = '0.0.0.0';
}
}
}
else
{
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_CLIENT_IP'))
{
$ip = getenv('HTTP_CLIENT_IP');
}
else
{
$ip = getenv('REMOTE_ADDR');
}
}
preg_match("/[\d\.]{7,15}/", $ip, $onlineip);
$ip = ! empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
return $ip;
}
}
/*获取真实ip结束*/
$reip = GetIP();
//相关参数md5加密
$allowT = md5($reip.$fs1);

if(!isset($_SESSION[$allowT])){
$_SESSION[$allowT] = time();
$counts=$count--;
if($counts=0){
die($reip.'亲,您今天机会用完了。。。');
}
}
else if(time() - $_SESSION[$allowT]-->$allowTime){
$_SESSION[$allowT] = time();
$counts=$count--;
if($counts=0){
die($reip.'亲,您今天机会用完了。。。');
}
}
//如果刷新过快,则直接给出404header头以及提示
else {header('HTTP/1.1 404 Not Found'); die($reip.'亲,您刷新过快了');}

?>


</body>
</html>



这刷新次数代码无效果的。。。
...全文
476 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aabbabababaa 2016-12-22
  • 打赏
  • 举报
回复
引用 5 楼 fdipzone 的回复:
是的,使用用户来做次数限制,是必须要登入。
登入的太麻烦,还是用IP将就下了,谢谢老大
傲雪星枫 2016-12-05
  • 打赏
  • 举报
回复
是的,使用用户来做次数限制,是必须要登入。
aabbabababaa 2016-12-04
  • 打赏
  • 举报
回复
引用 3 楼 fdipzone 的回复:
IP用处不大,可以模拟。 所以如果你是用户的,可以用用户id+次数来判断。当然必须是先登入有session了。
那我再研究下,谢谢老大
aabbabababaa 2016-12-03
  • 打赏
  • 举报
回复
引用 1 楼 fdipzone 的回复:
你这个应该是限制某个数值次数,这个很简单。但要用db保存 例如每个用户只有5次 表设计 uid 用户id quota 已使用次数 然后每使用一次对应uid的quota+1 当判断quota>=5时,返回已用完。
也是要取用户的IP值和SESSION么?
傲雪星枫 2016-12-03
  • 打赏
  • 举报
回复
IP用处不大,可以模拟。 所以如果你是用户的,可以用用户id+次数来判断。当然必须是先登入有session了。
傲雪星枫 2016-12-02
  • 打赏
  • 举报
回复
你这个应该是限制某个数值次数,这个很简单。但要用db保存 例如每个用户只有5次 表设计 uid 用户id quota 已使用次数 然后每使用一次对应uid的quota+1 当判断quota>=5时,返回已用完。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧