Skip to content

Instantly share code, notes, and snippets.

Detect google and yandex search bots (crawl, spider)

function detectSearchBot($ip, $agent, &$hostname)
{
    $hostname = $ip;

    // check HTTP_USER_AGENT what not to touch gethostbyaddr in vain
    if (preg_match('/(?:google|yandex)bot/iu', $agent)) {
 // success - return host, fail - return ip or false
@mrLexx
mrLexx / bot_detect.php
Created November 13, 2019 06:15
обнаружение ботов
<?php
//http://qaru.site/questions/60076/how-to-detect-search-engine-bots-with-php
if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) {
// is bot
}
if (preg_match('/apple|baidu|bingbot|facebookexternalhit|googlebot|-google|ia_archiver|msnbot|naverbot|pingdom|seznambot|slurp|teoma|twitter|yandex|yeti/i', $_SERVER['HTTP_USER_AGENT'])) {
// allowed bot
}
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@mrLexx
mrLexx / rotate_array.php
Created April 29, 2014 23:46
PHP: Rotate array
<?php
$keys = array_keys($arr);
$val = $arr[$keys[0]];
unset($arr[$keys[0]]);
$arr[$keys[0]] = $val;
@mrLexx
mrLexx / Vagrantfile
Last active March 8, 2017 16:03
PuPHPet Integration with hostsupdater
Vagrant.configure("2") do |config|
## Begin vagrant-hostsupdater
## https://github.com/cogitatio/vagrant-hostsupdater
## vagrant plugin install vagrant-hostsupdater
if Vagrant.has_plugin?("vagrant-hostsupdater") && configValues['apache']['install'] == '1'
config.hostsupdater.remove_on_suspend = true
config.hostsupdater.aliases = Array.new
configValues['apache']['vhosts'].each do |i, host|
@mrLexx
mrLexx / CodeLineNumber
Created February 6, 2014 02:07
Код с номерами строк. 1. Номера могут начинаться с какого угодно числа, могут разрываться, могут быть не числами (например, ... для обозначения того, что часть кода не приводится). 2. Номера не должны копироваться. 3. Длинные строки должны переноситься.
<style type="text/css">
.code {
font-family: Consolas, "Liberation Mono", Courier, monospace;
border-collapse: collapse;
line-height: 18px;
font-size: 13px;
}
.code th {
color: #333;