A question about PHP

Source: Internet
Author: User
A question about PHP
PHP Code
  
   $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) <3) {  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;}

Main function: in 3 seconds continuously refresh the page 5 times will point to the native http://127.0.0.1
The internet widely circulated a code, but obviously this code is wrong, because//has played a role in the annotation, then how to change this code to use it properly?
Not familiar with PHP, so please master correction, thank you, the points are not much, can only give 30 points.

------Solution--------------------
Quotation marks are wrong, the 1 floor of the code is quoted in Chinese single quotation marks, not in English single quotation marks ...
------Solution--------------------
Correct code:

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) <3) {
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;
}
?>
------Solution--------------------
Google a bit, this is a prevent CC program
Landlord provides the program in the local run error, slightly modified, tested to run

Session_Start (); Open session
$timestamp = time ();
$ll _nowtime = $timestamp;

Determine if the session exists if there is a value from session, if there is no initialization assignment
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;
}

Now time-Start login time to make a judgment if the login frequently jumps or otherwise assigns a value to the session
if (($ll _nowtime-$ll _lasttime) < 3) {
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 Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.