Google抓取工具,cron和代码标记工具 [英] Google crawler, cron and codeigniter sessions

查看:223
本文介绍了Google抓取工具,cron和代码标记工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Codeigniter 2.0 网络应用程序,我正在使用带有数据库选项的会话库,因此对于网站上的每个连接,我都有一个名为'ci_sessions'表示存储:




  • Session_id

  • IP地址

  • User_agent

  • Last_activity

  • User_data



我有两个问题:


  1. Google bot with IP 66.249.72.152

  2. Cron with IP 0.0.0.0

每当我的伺服器执行cron或每次google漫游器检索我的网页时,都会建立一个新工作阶段。所以我有数百个相同的会话与IP 0.0.0.0 和数百与IP 66.249.72.152 p>

有谁知道如何阻止机器人或cron创建会话?或者如果这不能做...有谁知道如何自动删除这些会话每隔一段时间?谢谢!

解决方案

我建议不要修改核心文件,我建议扩展会话类,因此,接下来在 ./ app / libraries / 中创建 MY_Session.php 文件,然后粘贴下一个代码

 <?php if(!defined('BASEPATH'))exit('不允许直接脚本访问); 
/ **
* -------------------------------------- ----------------------------------
* CI会话类扩展
* - -------------------------------------------------- --------------------
*
* /
class MY_Session extends CI_Session {
/ **
* sess_update()
*
*如果它在cli环境中,不创建会话
*
* @access public
* @return void
* /
public function sess_create()
{
$ CI = get_instance();
$ ip_address = $ CI-> input-> ip_address();

if(($ ip_address!='0.0.0.0'&& $ CI-> input-> user_agent()!='0')|| $ ip_address!= '66 .249 .72.152'){
parent :: sess_create();
}
}
}

/ *文件结束MY_Session.php * /
/ *位置:./app/libraries/MY_Session.php * /
?>

这项工作


I am running a Codeigniter 2.0 web app, and I am using the sessions library with the DB option on, so for every connection on my website I have a MySQL table called 'ci_sessions' that stores:

  • Session_id
  • IP address
  • User_agent
  • Last_activity
  • User_data

And I have two issues:

  1. Google bot with IP 66.249.72.152
  2. Cron with IP 0.0.0.0

Everytime my server runs the cron or every time the google bot crawls my page a new session is created. So I have hundreds of identical sessions with the IP 0.0.0.0 and hundreds with the IP 66.249.72.152.

Does anyone know how to stop the bot or the cron from creating sessions? Or if this can not be done... does anyone know how to automatically delete these sessions every once in a while? Thanks!

解决方案

I suggest not to modify core files, I recommend to extend the session class, so do the next thing create MY_Session.php file in ./app/libraries/ and paste the next code

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * ------------------------------------------------------------------------
 * CI Session Class Extension
 * ------------------------------------------------------------------------
 *
*/
class MY_Session extends CI_Session {
   /**
    * sess_update()
    * 
    * Do not create session if it's in the cli environment
    *
    * @access    public
    * @return    void
    */
    public function sess_create() 
    {
        $CI         = get_instance();
        $ip_address = $CI->input->ip_address();

        if ( ($ip_address != '0.0.0.0' && $CI->input->user_agent() != '0') || $ip_address != '66.249.72.152'){
            parent::sess_create();
        }
    }
}

/* End of file MY_Session.php */
/* Location: ./app/libraries/MY_Session.php */
?>

this works

这篇关于Google抓取工具,cron和代码标记工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆