The implementation code of PHP to prevent CC attacks is "if (session_is_registered('ll_lasttime')){$ll_lasttime = $_SESSION['ll_lasttime'];$ll_times =...}".
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
What is the PHP anti-CC attack implementation code? ?
PHP anti-CC attack implementation code
The so-called CC attack is that the other party uses a program or some agents to continuously access your website, causing you to The website cannot handle it and is in a crashed state
At this time, your statistical system (may be Quantum, Baidu, etc.) will of course not be able to count. However, we can use some anti-attack software to achieve this, but the effect is sometimes not obvious.
Below I provide a piece of PHP code, which can have a certain anti-CC effect.
Main function: Refreshing the page more than 5 times within 3 seconds will point to the local http://127.0.0.1
The code is as follows:
$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; }
The following is the netizen’s Reply:
SESSION relies on COOKIE. What should I do if I block COOKIE?
TCP/IP -> apache -> php This process has consumed a lot of things. At this point, there are no more calculation operations and MYSQL connections.
Just these few lines of code , cannot solve the problem. At most, it is disabled for those operations where you press F5 to refresh the page in the browser.
Therefore, it is recommended that everyone install a firewall to prevent CC attacks on the server, so that the effect will be better.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the PHP anti-CC attack implementation code?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
