PHP prevents malicious code from refreshing a page

Source: Internet
Author: User
    1. Session_Start ();
    2. $k =$_get[' K '];
    3. $t =$_get[' t '];
    4. $allowTime = 1800;//anti-refresh Time
    5. $ip = Get_client_ip ();
    6. $allowT = MD5 ($ip. $k. $t);
    7. if (!isset ($_session[$allowT]))
    8. {
    9. $refresh = true;
    10. $_session[$allowT] = time ();
    11. }elseif (Time ()-$_session[$allowT]> $allowTime) {
    12. $refresh = true;
    13. $_session[$allowT] = time ();
    14. }else{
    15. $refresh = false;
    16. }
    17. ?>
Copy Code

IE6 submitted two times I have also encountered, is generally used in the picture instead of submit, the picture has a submit (), this will be submitted two times, if only submit button I did not encounter the submission two times the situation.

Now tidy up: The method is basically said to be almost the page that is received is 2.php divided into two parts, part of the processing of the variables submitted, part of the page processing variable is finished with the header ("Location:". $_server[' Php_self ') Jump to Self page This section to make a judgment, if there is no post variables to skip. Of course, you can also jump to other pages. Jumping to another page will have a problem when you return, it is recommended to do in a PHP file. If the previous page passes through the variable does not meet the requirements can be forced to return

Copy Code

A general idea. The 2.php process

    1. if (Isset ($_post))
    2. {Receive variable
    3. If (variable does not meet the requirements)
    4. Else
    5. Manipulating data
    6. ...
    7. if (operation completed)
    8. Header ("Location:". $_server[' php_self ');
    9. }
Copy Code
  • 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.