Plugin Directory

Changeset 1127609


Ignore:
Timestamp:
04/04/2015 09:00:17 AM (11 years ago)
Author:
antsanchez
Message:

Avoid showing the message to Bots like Google or Bing

Location:
easy-cookie-law/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • easy-cookie-law/trunk/easy-cookie-law.php

    r1117527 r1127609  
    33 * Plugin Name: Easy Cookie Law
    44 * Description: Minimal code to make sure your website repect the coockie law
    5  * Version: 0.1.1
     5 * Version: 0.1.2
    66 * Author: Antonio Sanchez
    77 * Author URI: http://antsanchez.com
     
    208208/**
    209209*
     210* Function to check if the visitor is a Bot
     211*
     212*/
     213function ecl_crawler_detect($USER_AGENT){
     214    $bots_list = array(
     215        'Google'=> 'Googlebot',
     216        'Bing' => 'bingbot',
     217        'Rambler'=>'Rambler',
     218        'Yahoo'=> 'Slurp',
     219        'AbachoBOT'=> 'AbachoBOT',
     220        'accoona'=> 'Accoona',
     221        'AcoiRobot'=> 'AcoiRobot',
     222        'ASPSeek'=> 'ASPSeek',
     223        'CrocCrawler'=> 'CrocCrawler',
     224        'Dumbot'=> 'Dumbot',
     225        'FAST-WebCrawler'=> 'FAST-WebCrawler',
     226        'GeonaBot'=> 'GeonaBot',
     227        'Gigabot'=> 'Gigabot',
     228        'Lycos spider'=> 'Lycos',
     229        'MSRBOT'=> 'MSRBOT',
     230        'Altavista robot'=> 'Scooter',
     231        'AltaVista robot'=> 'Altavista',
     232        'ID-Search Bot'=> 'IDBot',
     233        'eStyle Bot'=> 'eStyle',
     234        'Scrubby robot'=> 'Scrubby',
     235    );
     236   
     237    $regexp= '/'.  implode("|", $bots_list).'/';
     238    if ( preg_match($regexp, $USER_AGENT)){
     239        return true;
     240        // It is a bot
     241    }else{
     242        return false;
     243        // It is not
     244    }
     245}
     246 
     247/**
     248*
    210249* Creates cookie
    211250*
     
    213252function ecl_cookie_test(){
    214253
    215     $name = "easy-cookie-law";
    216     session_start();
    217     global $ecl_user;
    218     if(isset($_COOKIE[$name])){
    219         $ecl_user = $_COOKIE[$name];
    220         if($ecl_user == 1){
    221             setcookie($name, 3, time() + (86400 * 30), "/");
    222             $ecl_user = 3;
     254    if(!ecl_crawler_detect($_SERVER['HTTP_USER_AGENT'])){
     255        $name = "easy-cookie-law";
     256        session_start();
     257        global $ecl_user;
     258        if(isset($_COOKIE[$name])){
     259            $ecl_user = $_COOKIE[$name];
     260            if($ecl_user == 1){
     261                setcookie($name, 3, time() + (86400 * 30), "/");
     262                $ecl_user = 3;
     263            }
     264        }else{
     265            setcookie($name, 1, time() + (86400 * 30));
     266            $ecl_user = 1;
    223267        }
    224     }else{
    225         setcookie($name, 1, time() + (86400 * 30));
    226         $ecl_user = 1;
    227268    }
    228269}
  • easy-cookie-law/trunk/readme.txt

    r1117527 r1127609  
    44Requires at least: 3.0.1
    55Tested up to: 4.1.1
    6 Stable tag: 0.1.1
     6Stable tag: 0.1.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515Easy Cookie Law allows you to easily comply with the european cookie law, showing
    1616a notice to the user only the very first time that visits your website.
    17 Message, position and the style can be easily modified through the plugin menu.
     17Message, position and the style can be easyly modified through the plugin menu.
    1818
    1919It helps you with SEO, since the plugin will not add any CSS stylesheet or Javascript file,
     
    3838will not be shown again.
    3939
     40If the visitor is a bot, like Google or Bing, the message won't be shown.
     41
    4042= Why am I not seeing the message? =
    4143
Note: See TracChangeset for help on using the changeset viewer.