Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Session spammed by bots
#1

hello,
my website has visits from various search engine bots. I would like to ignore the bots from the session table.

i tried with this library https://github.com/donjakobo/codeigniter-clean-sessions but didn't work with ci 3.

Any help?
Reply
#2

I'm not sure how well this would work, as it would depend at least somewhat on your site's ability to continue to function without a session, but you could extend the sessions library in a similar fashion to the library you linked by creating a file in /application/libraries/Session/MY_Session.php:
PHP Code:
<?php 
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Session extends CI_Session
{
    public function 
__construct(array $params = array())
    {
        
$CI get_instance();
        
$CI->load->library('user_agent');
        if (
$CI->agent->is_robot()) {
            
log_message('debug''Session: Robot detected, initialization aborted.');
            return;
        }
        
        
parent::__construct($params);
    }


This also depends on the ability to access the loader (and, in turn, the user_agent library) at the time the session library is loaded.

Note that this should be the entire contents of the new file. All it does is load the user_agent library to check whether it can identify a robot. If it identifies a robot, it logs a debug message and exits. Otherwise, it turns control back over to the parent, making sure to pass along any parameters which may have been passed by the loader.
Reply
#3

mwhitney, thank u. I use this construction, work it.
but I edit this array list
maybe somebody need this.

PHP Code:
$robots = array(
'googlebot' => 'Googlebot',
'yandex' => 'YandexBot',
'msnbot' => 'MSNBot',
'yahoo' => 'Yahoo',
'baiduspider' => 'Baiduspider',
'bingbot' => 'Bing',
'slurp' => 'Inktomi Slurp',
'ask jeeves' => 'Ask Jeeves',
'fastcrawler' => 'FastCrawler',
'infoseek' => 'InfoSeek Robot 1.0',
'lycos' => 'Lycos',
'mediapartners-google' => 'MediaPartners Google',
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
'adsbot-google' => 'AdsBot Google',
'feedfetcher-google' => 'Feedfetcher Google',
'curious george' => 'Curious George',
'sputnikbot' => 'Sputnik',
'sosospider' => 'Soso'
); 
Reply
#4

I am developing an Anti-Scraping library

https://github.com/terrylinooo/Codeignit...ng-Library

Just completed the document, still testing it. I will uplodad the library soon..
Personal blog: https://terryl.in
My personal project is called Dictpedia is currently using Codeigniter 3, welcome.
Reply
#5

(This post was last modified: 05-21-2016, 01:14 PM by skunkbad.)

Maybe it is a simple solution where you have a blacklist in MY_Session.php:


Code:
<?php
class MY_Session extends CI_Session {

    public function __construct(array $params = array())
    {
        $CI =& get_instance();

        $blacklist = [
            '123.255.123.255',
            'MegaBot',
            'Whatever'
        ];

        foreach( $blacklist as $bot )
        {
            if(
                stripos( $_SERVER['HTTP_USER_AGENT'], $bot ) !== FALSE OR
                $CI->input->ip_address() == $bot
            )
            {
                return;
            }
        }

        parent::__construct($params);
    }
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB