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.

help needed with a snippet of PHP code.

Discussion in 'PHP' started by dakar, Jan 29, 2005.

  1. #1
    I'm by no way a php programmer so this will seem silly to those that have more of a clue than I do...

    I've got a hack installed on my forums that tracks SE bots visits, but I've found it's not as complete as I'd like... speficially this snippet of code:

    
    $google_visit_counter = $board_config['google_visit_counter']; 
    
    $tmp_list = explode(".", $_SERVER['$REMOTE_ADDR']); 
    
    if (preg_match("/googlebot/i", $HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
     
    $sql = "UPDATE " . CONFIG_TABLE . " 
    SET config_value = '" . ($google_visit_counter + 1) . "' 
    WHERE config_name = 'google_visit_counter'"; 
    if( !($result = $db->sql_query($sql)) ) 
    { 
    
    Code (markup):
    is there a simple way to add to the query to include ''Mediapartners-Google" as well to the for the preg_match so that it will increment the counter for these hits as well?

    Thanks in advance...
     
    dakar, Jan 29, 2005 IP
  2. john_loch

    john_loch Rodent Slayer

    Messages:
    1,294
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    138
    #2
    The following should do it - though I've not tested it.

    
    $google_visit_counter = $board_config['google_visit_counter']; 
    
    $tmp_list = explode(".", $_SERVER['$REMOTE_ADDR']); 
    
    if (preg_match("/googlebot/i", $HTTP_SERVER_VARS['HTTP_USER_AGENT']) || preg_match("/Mediapartners-Google/i", $HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
     
    $sql = "UPDATE " . CONFIG_TABLE . " 
    SET config_value = '" . ($google_visit_counter + 1) . "' 
    WHERE config_name = 'google_visit_counter'"; 
    if( !($result = $db->sql_query($sql)) ) 
    { 
    
    Code (markup):
    Cheers,

    JL
     
    john_loch, Jan 29, 2005 IP
  3. dakar

    dakar Active Member

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    Thanks JL, i knew it had to be simple, just had no clue to the syntax, I'll give that a whirl and see what comes of it.
    Now I just need to wait for G to come poking around to see if it'll work.

    Thanks!
     
    dakar, Jan 30, 2005 IP
  4. slipwalker

    slipwalker Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    actually you dont need to wait for googlebot to spider around your site, you could use GNU/wget with "--user-agent=googlebot" to test this sort of thing...
    at least that's how i do it...

    ;)
     
    slipwalker, Feb 2, 2005 IP