Home > Backend Development > PHP Problem > How to limit ua in php

How to limit ua in php

(*-*)浩
Release: 2023-02-26 17:40:02
Original
4625 people have browsed it

UA is the user agent (User-Agent), and the server identifies the visitor's identity through UA. When a website returns an abnormal page (such as 403, 500) or jumps to other pages for access to a designated UA, it is a UA ban.

How to limit ua in php

Restrictions user_agent:

user_agent (user agent): refers to browser (search engine) information including hardware platform, System software, application software and personal user preferences. (Recommended learning: PHP Video Tutorial)

When a hacker attacks your server with CC, check the log and find that user_agent is consistent, and user_agent appears multiple times in one second, so User_agent must be restricted

   <IfModule mod_rewrite.c> //使用rewrite模块
        RewriteEngine on
        RewriteCond %{HTTP_USER_AGENT}  .*curl.* [NC,OR] //定义user_agent条件,OR表示两条件之间是或者的意思,NC表示忽略大小写
        RewriteCond %{HTTP_USER_AGENT}  .*baidu.com.* [NC] //定义user_agent条件
        RewriteRule  .*  -  [F] // 规则 [F] 表示forbidden(403)
    </IfModule>
Copy after login

We still use rewrite modul

RewriteCond %{HTTP_USER_AGENT}  .*curl.* [NC,OR]   //匹配Curl的访问   [NC,OR] NC:忽略大小写。 OR:是或者的意思,要么这一条,要么下一条满足情况
RewriteCond %{HTTP_USER_AGENT}  .*baidu.com.* [NC]
RewriteRule  .*  -  [F]   // F:Forbidden 禁止
Copy after login

As long as you use curl and baidu.com to attack, it will not jump directly. Just ban it!

[[email protected] test3.com]# curl -x127.0.0.1:80 www.test3.com
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don&#39;t have permission to access /
on this server.<br />
</p>
</body></html>
Copy after login

The above is the detailed content of How to limit ua in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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