Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of recording spider crawl log by ThinkPHP6

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

这篇文章主要介绍"ThinkPHP6记录蜘蛛爬取日志的方法是什么",在日常操作中,相信很多人在ThinkPHP6记录蜘蛛爬取日志的方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"ThinkPHP6记录蜘蛛爬取日志的方法是什么"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

thinkphp6记录百度蜘蛛日志:

在控制器的父类如IndexBase中写入以下代码,所有前端控制器继承这个控制器

public function initialize() { parent::initialize(); // TODO: Change the autogenerated stub if ($this->Config['web_status'] == 0) { // 判断是否关闭网站 die('网站已经关闭'); } $this->baiduLog(); } protected function baiduLog() { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); $url = $this->request->controller() . "/" . $this->request->action(); $param = input("param.","","htmlspecialchars"); $url = (string) url($url,$param); $ip = get_real_ip(); $title = ""; if (strpos($useragent, 'googlebot') !== false){ $title = 'Google'; } elseif (strpos($useragent, 'baiduspider') !== false){ $title = 'Baidu'; } elseif (strpos($useragent, 'msnbot') !== false){ $title = 'Bing'; } elseif (strpos($useragent, 'slurp') !== false){ $title = 'Yahoo'; } elseif (strpos($useragent, 'sosospider') !== false){ $title = 'Soso'; } elseif (strpos($useragent, 'sogou spider') !== false){ $title = 'Sogou'; } elseif (strpos($useragent, 'yodaobot') !== false){ $title = 'Yodao'; } elseif (strpos($useragent, 'googlebot') !== false){ $title = 'Google'; } elseif (strpos($useragent, 'baiduspider') !== false){ $title = 'Baidu'; } else {// $title = $useragent; // 不怕数据大的话可以取消注释,记录所有访问日志 } if (!empty($title)) { BaiduLog::create(["title"=>$title,"href"=>$url,"ip"=>$ip]); } }

以上就是thinkphp6记录百度蜘蛛爬行日志的方法,

get_real_ip()

是获取客户真实IP的自定义函数。

到此,关于"ThinkPHP6记录蜘蛛爬取日志的方法是什么"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report