Geo targetng for Wordpress header

Discussion in 'PHP' started by chavdar, May 21, 2010.

  1. #1
    Anybody know the way how to load java script in the header-a of Wordpress as anyone came from one country and another java script when came from another country.
    Example:
    From US loads a java script in header.php, but if someone from UK visits the blog another java script loads in header.php. Excuse me for bad english.
    So this will be a geo targeting i mean.
     
    chavdar, May 21, 2010 IP
  2. sumanhaldar

    sumanhaldar Active Member

    Messages:
    148
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    sumanhaldar, May 21, 2010 IP
  3. chavdar

    chavdar Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    chavdar, May 21, 2010 IP
  4. chavdar

    chavdar Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    chavdar, May 21, 2010 IP
  5. chavdar

    chavdar Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Please help with any suggestions cause this plugin dont work for me?
     
    chavdar, May 21, 2010 IP
  6. Wulkan91

    Wulkan91 Member

    Messages:
    420
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #6
    I'm kinda looking for the same thing.
    But for content instead.
    So that US visitors see another content than European visitors does etc.
     
    Wulkan91, Aug 14, 2010 IP
  7. hassanahmad2

    hassanahmad2 Active Member

    Messages:
    243
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #7
    You can determine country of the visitor by using this simple function:

    
    function GetUserCountry() {
    
       $ip = $_SERVER['REMOTE_ADDR'];
       $iptemp = explode('.', $ip);
       $ipdec  = $iptemp[0] * 256 * 256 * 256 +
                 $iptemp[1] * 256 * 256 +
                 $iptemp[2] * 256 +
                 $iptemp[3];
       $file  = file_get_contents('ips.txt');
       if (!strlen($file)) return FALSE;
    
       $lines = explode("\n", $file);
    
       foreach($lines as $line)
       {
          if (strlen($line))
          {
             $parts = explode(',', trim($line));
    
             if ($ipdec >= $parts[0] && $ipdec <= $parts[1])
                return $parts[2];
          }
       }
    
       return FALSE;
    }
    
    Code (markup):
    You will have to download this zip file, extract the text file and put it in the same folder as the script.

    Here's a sample usage of the function:
    
    <?php if (GetUserCountry() == "United States") { ?>
    
         <b>Content for United States.</b>
    
    <?php } else { ?>
    
         <b>Content for other countries</b>
    
    <?php } ?>
    
    Code (markup):
    Hope it helps.
     
    hassanahmad2, Aug 15, 2010 IP