Answer the question
In order to leave comments, you need to log in
What is the fastest substring search function in PHP?
Greetings
There is a small script for blocking unwanted bots by User-Agent:
// массив нежелательных значений
$bad_agents = array('python', 'alexa', 'baidu',);
// получаем user-agent
$agent = $_SERVER['HTTP_USER_AGENT'];
foreach ($bad_agents as $agent) {
if( >>> ??? <<< ){
die();
}
}
...
138.197.65.234 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
45.55.138.142 Netcraft SSL Server Survey - contact [email protected]
91.224.140.214
212.109.217.105 Needle/1.6.0 (Node.js v6.5.0; linux x64)
138.197.13.157 Python-urllib/2.7
...
Answer the question
In order to leave comments, you need to log in
php.net/manual/en/function.strpos.php
foreach ($bad_agents as $bad) {
if(strpos($agent, $bad) !== false){
die();
}
}
// массив нежелательных значений
$bad_agents = array('python', 'alexa', 'baidu',);
// получаем user-agent
$agent = $_SERVER['HTTP_USER_AGENT'];
if(in_array($agent, $bad)){
die();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question