近期有做泛目录的朋友咨询家兴网络想要一个搜索蜘蛛抓取不跳转,真实用户访问就跳转到指定广告网址页面php代码,根据这位朋友家兴网络去开源论坛找了个现成的php代码,这位做泛目录的朋友用了觉得不错,今天分享出来,希望对大家有所帮助!

PHP代码实现用户访问跳转到指定网站,蜘蛛访问不跳转并记录!.png

PHP记录蜘蛛,并识别访客跳转指定网站代码示例:

$useragent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT']));if (strpos($useragent, 'googlebot') !== false) {
    $bot = 'Google';} elseif (strpos($useragent, 'mediapartners-google') !== false) {
    $bot = 'Google Adsense';} elseif (strpos($useragent, 'baiduspider') !== false) {
    $bot = 'Baidu';} elseif (strpos($useragent, 'sogou spider') !== false) {
    $bot = 'Sogou';} elseif (strpos($useragent, 'sogou web') !== false) {
    $bot = 'Sogou web';} elseif (strpos($useragent, 'sosospider') !== false) {
    $bot = 'SOSO';} elseif (strpos($useragent, '360spider') !== false) {
    $bot = '360Spider';} elseif (strpos($useragent, 'yahoo') !== false) {
    $bot = 'Yahoo';} elseif (strpos($useragent, 'msn') !== false) {
    $bot = 'MSN';} elseif (strpos($useragent, 'msnbot') !== false) {
    $bot = 'msnbot';} elseif (strpos($useragent, 'sohu') !== false) {
    $bot = 'Sohu';} elseif (strpos($useragent, 'yodaoBot') !== false) {
    $bot = 'Yodao';} elseif (strpos($useragent, 'twiceler') !== false) {
    $bot = 'Twiceler';} elseif (strpos($useragent, 'ia_archiver') !== false) {
    $bot = 'Alexa_';} elseif (strpos($useragent, 'iaarchiver') !== false) {
    $bot = 'Alexa';} elseif (strpos($useragent, 'slurp') !== false) {
    $bot = '雅虎';} elseif (strpos($useragent, 'yisouspider') !== false) {
    $bot = '神马';} elseif (strpos($useragent, 'bot') !== false) {
    $bot = '其它蜘蛛';}if (isset($bot)) {
    //是蜘蛛,写出日志
     $fp = @fopen('zhizhu.txt','a');
     fwrite($fp,date('Y-m-d H:i:s')." ".$_SERVER["REMOTE_ADDR"]." ".$bot.
          " ".'http://'.$_SERVER['SERVER_NAME'].
          $_SERVER["REQUEST_URI"]."
");
     fclose($fp);} else {
    //不是蜘蛛,直接跳转
    header('Location: http://www.zzzzjy.cn/');


如果你觉得这篇文章对你有所帮助,或者对家兴网络分享的这段PHP代码有任何建议和想法,欢迎在评论区留言,分享你的想法。

无论是你是长期从事网页开发的工作者,还是只是一个初学者,相信你会对这篇文章的内容有自己的理解和感悟。

同时如果你喜欢这篇文章,也请分享给你的朋友们,让更多的人看到这篇文章,一起感受网页开发的魅力。

最后,感谢家兴网络提供的这段PHP代码示例,也感谢所有在开源论坛分享的人们,是你们的无私奉献,让我们有了更多的学习资源和机会。