Как в cURL подменить User Agent
В редакторе
Как в cURL подменить User Agent
Brain_Script
1703
2016-09-03 12:19:11
<?php
function vzglyanut_kak_robot($url, $bot) {
$user_agents = array(
"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)",
"Mozilla/5.0 (compatible; Mail.RU/2.0)",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0"
);
print "<h1>{$user_agents[$bot]}</h1>";
$kurl = curl_init();
curl_setopt($kurl, CURLOPT_URL, $url);
curl_setopt($kurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($kurl, CURLOPT_FAILONERROR, true);
curl_setopt($kurl, CURLOPT_TIMEOUT, 30);
curl_setopt($kurl, CURLOPT_POST, false);
curl_setopt($kurl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($kurl, CURLOPT_USERAGENT, $user_agents[$bot]);
$stranica = curl_exec($kurl);
return $stranica;
}
$url = "http://code-snippets.ru";
print vzglyanut_kak_robot($url, 0);
?>
Войдите для добавления комментария.