PHP prevents the site from being refreshed by summarizing the method, PHP prevent refresh Rollup _php tutorial

Source: Internet
Author: User

PHP prevents the site from being refreshed by summarizing the method, PHP prevents refresh Rollup


This article explains how PHP prevents Web sites from being refreshed. Share to everyone for your reference. Here's how:

For stations like WP construction, frequent refreshes can lead to a tight database. The following is a code to prevent frequent refresh caused by the freezing situation.

Method One, the code is as follows:
Copy CodeThe code is as follows: <?php
Session_Start ();
$k =$_get[' K '];
$t =$_get[' t '];
$allowTime = 1800;//anti-refresh Time
$ip = Get_client_ip ();
$allowT = MD5 ($ip. $k. $t);
if (!isset ($_session[$allowT]))
{
$refresh = true;
$_session[$allowT] = time ();
}elseif (Time ()-$_session[$allowT]> $allowTime) {
$refresh = true;
$_session[$allowT] = time ();
}else{
$refresh = false;
}
?>
Method Two, the code is as follows:
Copy CodeThe code is as follows: <?php
Session_Start ();
$allow _sep = "2";
if (Isset ($_session["Post_sep"))
{
if (Time ()-$_session["Post_sep"] < $allow _sep)
{
Exit ("Please do not frequent refresh, rest 2 seconds and then refresh it");
}
Else
{
$_session["post_sep"] = time ();
}
}
Else
{
$_session["post_sep"] = time ();
}
?>
Method Three, the code is as follows:
Copy CodeThe code is as follows: <?php
Session_Start ();
if (!emptyempty ($_post[name])) {
$data = $_post[name];
$tag = $_post[tag];
if ($_session[status]== $tag) {
Echo $data;
}else{
echo "not allowed to refresh!" ";
}
}
$v = Mt_rand (1,10000);
?>

<?php
Echo $v;
$_session[status] = $v;
?>

Note: The code is there, but there are some other things to apply to WordPress.

Because the above code is based on session validation, assuming that you refresh the page within 2 seconds, then he will execute the exit () function to output a message and exit the current script, so the following content is not loaded, so this code is best placed in the header, first let the code to execute, and then load the other things.

If the code is placed in the footer, the results of the entire page loaded only in the last line output "Please do not frequent refresh", put in the header, the effect is better, want to see the effect of the words of two F5 bar.

Of course, the best thing to do is to create a new PHP file and then call it in the header.

There are two benefits to this:

One is to modify the function code convenient, do not have to open the header file every time, but also not afraid to change the code elsewhere, the second is that once the error, you can quickly modify and check, and even directly delete the file, the code is as follows:
Copy the Code code as follows: <?php
Include (' includes/forbiddencc.php ');
?>

Note here that you must call the front of all pages.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/920625.html www.bkjia.com true http://www.bkjia.com/PHPjc/920625.html techarticle PHP prevents the site from being refreshed method summary, PHP prevent refresh Summary This article describes how PHP prevents the site from being refreshed. Share to everyone for your reference. Here's how it works: For ...

  • 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.