1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

removing session ID for Googlebot ?

Discussion in 'Programming' started by Percept, Sep 25, 2004.

  1. #1
    
    
    	if($_SERVER['HTTP_USER_AGENT'] != 'Googlebot'){
    	session_start();
    	}
    
    
    PHP:
    Would this do the trick ?
    SEMrush
     
    Percept, Sep 25, 2004 IP
    SEMrush
  2. Sholva

    Sholva Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't do any sites that do sessions with php, but I'd assume you have to use a regular expression instead of just 'GoogleBot' because they have different version numbers and the "new" one right?

    something like !~ /googlebot/i

    Just an idea.
     
    Sholva, Sep 25, 2004 IP
  3. Sholva

    Sholva Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think preg_match is what you would use in php, (I'm a perl coder not php)

    edit: try this?
    if(preg_match("/googlebot/i", $_SERVER['HTTP_USER_AGENT']) != 1){
        session_start();
        } 
    Code (markup):
     
    Sholva, Sep 25, 2004 IP
  4. Percept

    Percept Peon

    Messages:
    143
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok, I will check the user agent string with regular expressions then ... thanks.
     
    Percept, Sep 25, 2004 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #5
    strpos or strstr would be a lot faster than preg_match:
    
    if( strpos( $_SERVER['HTTP_USER_AGENT'], "Googlebot" ) !== false ) {
      // we've found a googlebot
    }else{
      // session initialization code
    }
    Code (markup):
     
    exam, Sep 25, 2004 IP
  6. Sholva

    Sholva Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm just curious, besides the fact that I used a case insensitivity in my reg exp. example, how much faster would strpos be? I'm unsure of how efficient the reg exp engine php is, but it's pretty darn fast in perl it only does what it needs to.

    Having said that I'm not to try to claim it's not faster, I'd just like to hear why. :)
     
    Sholva, Sep 25, 2004 IP
  7. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #7
    > I used a case insensitivity in my reg exp
    you can also use stripos or stristr for a case-insensitive search. But why do you need a case/insensitive match? I don't see why G would change the UA from Googlebot to googlebot.

    Why is it faster? Probably because it doesn't have to run the string through a reg. expression parser. How much faster is it? I don't know. Here is a quote from php.net (http://www.php.net/manual/en/function.preg-match.php)
     
    exam, Sep 25, 2004 IP
  8. Sholva

    Sholva Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yeah the quote is enough to answer my question thanks.

    What I was referring to with the case option was that having already put some code up there that was case insensitive, that it would be slower than something case specific. That's all. The reason I did it in the first place? Habit I guess.
     
    Sholva, Sep 25, 2004 IP