Home > Backend Development > PHP Tutorial > 一个关于PHP的有关问题

一个关于PHP的有关问题

WBOY
Release: 2016-06-13 10:37:06
Original
855 people have browsed it

一个关于PHP的问题

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$P_S_T = $t_array[0] + $t_array[1];$timestamp = time();session_start();$ll_nowtime = $timestamp ;if (session_is_registered(‘ll_lasttime’)){  $ll_lasttime = $_SESSION['ll_lasttime'];  $ll_times = $_SESSION['ll_times'] + 1;  $_SESSION['ll_times'] = $ll_times;}else{  $ll_lasttime = $ll_nowtime;  $ll_times = 1;  $_SESSION['ll_times'] = $ll_times;  $_SESSION['ll_lasttime'] = $ll_lasttime;}if (($ll_nowtime – $ll_lasttime)=5){    header(sprintf(“Location: %s”,’http://127.0.0.1′));    exit;  }}else{  $ll_times = 0;  $_SESSION['ll_lasttime'] = $ll_nowtime;  $_SESSION['ll_times'] = $ll_times;}
Copy after login

主要功能:在3秒内连续刷新页面5次以上将指向本机 http://127.0.0.1
网上广为流传的一份代码,但是显然这个代码是错的,因为//已经起到的注释作用,那么怎么改这个代码才能正常使用呢?
不怎么熟悉PHP,所以请高手更正一下,谢谢,分不多了,只能给30分了。

------解决方案--------------------
引号错误吧,1楼的代码的引号是中文的单引号,不是英文的单引号。。。
------解决方案--------------------
正确代码:

date_default_timezone_set('PRC');
$timestamp = time();
session_start();
$ll_nowtime = $timestamp ;
if (isset($ll_nowtime)){
$ll_lasttime = $_SESSION['ll_lasttime'];
$ll_times = $_SESSION['ll_times'] + 1;
$_SESSION['ll_times'] = $ll_times;
}else{
$ll_lasttime = $ll_nowtime;
$ll_times = 1;
$_SESSION['ll_times'] = $ll_times;
$_SESSION['ll_lasttime'] = $ll_lasttime;
}

if (($ll_nowtime-$ll_lasttime) if ($ll_times>=5){
header(sprintf("Location: %s",'http://127.0.0.1'));
exit();
}
}else{
$ll_times = 0;
$_SESSION['ll_lasttime'] = $ll_nowtime;
$_SESSION['ll_times'] = $ll_times;
}
?>
------解决方案--------------------
google一下,这是一个防止cc程序
楼主提供的程序在本地运行报错,稍微修改了一下,经测试可以运行

session_start(); //开启session
$timestamp = time();
$ll_nowtime = $timestamp ; 
 
 //判断session是否存在 如果存在从session取值,如果不存在进行初始化赋值
if ($_SESSION){
$ll_lasttime = $_SESSION['ll_lasttime'];
$ll_times = $_SESSION['ll_times'] + 1;
$_SESSION['ll_times'] = $ll_times;
}else{
$ll_lasttime = $ll_nowtime;
$ll_times = 1;
$_SESSION['ll_times'] = $ll_times;
$_SESSION['ll_lasttime'] = $ll_lasttime;
}

//现在时间-开始登录时间 来进行判断 如果登录频繁 跳转 否则对session进行赋值 
if(($ll_nowtime - $ll_lasttime) if ($ll_times>=5){
header("location:Http://www.baidu.com"); 
exit;
}
}else{
$ll_times = 0;
$_SESSION['ll_lasttime'] = $ll_nowtime;
$_SESSION['ll_times'] = $ll_times;
}
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template