LP GEO block code

Discussion in 'General Programming Chat' started by mgmedia, Jun 6, 2014.

  1. mgmedia

    mgmedia Newbie

    Joined:
    Sep 21, 2013
    Messages:
    14
    Likes Received:
    0
    What up guys,

    can anyone help me with this?

    how can I hard code a maxmind geoblocker onto an LP, in order to block specific GEO's?

    Thanks in advance
     
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    975
    Likes Received:
    682
    Occupation:
    Web/Bot Developer
    Code:
    <?php
    
    
    // Configure the URL to the geolocation service.
    $token       = 'MaxMind user token';
    $address     = 'MaxMind URL';
    $remote_ip   = get_remote_ip_address();
    $service_url = $address . '?l=' . $token . '&i=' . $remote_ip;
    
    
    // Call the web service using the configured URL.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $service_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ws_response = curl_exec($ch);
    
    
    $edge_geo = $ws_response;
    
    
    echo '<p>The country being blocked is: ' . strtoupper($blocked_geo) . '</p>';
    
    
    if ($edge_geo != strtoupper($blocked_geo))
    {
       echo '<p>Your country is: ' . strtoupper($edge_geo) . '</p>';
       echo '<p>You are not blocked.</p>';
    }
    else
    {
       echo '<p>Your country is: ' . strtoupper($edge_geo) . '</p>';
       echo '<p>You are blocked.</p>';
    }
    
    
    // Function definitions
    
    
    function get_remote_ip_address()
    {
       // Check to see if an HTTP_X_FORWARDED_FOR header is present.
    
    
       if($_SERVER['HTTP_X_FORWARDED_FOR'])
    
    
       {
       
          // If the header is present, use the last IP address.
          $temp_array      = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
          $temp_ip_address = $temp_array[count($temp_array) - 1];  
       }
       else
       {
          // If the header is not present, use the 
          // default server variable for remote address.
          $temp_ip_address = $_SERVER['REMOTE_ADDR'];
       }
    
    
       return $temp_ip_address;
    }
    
    
    ?>
    
     
  3. mgmedia

    mgmedia Newbie

    Joined:
    Sep 21, 2013
    Messages:
    14
    Likes Received:
    0
    Thank you kind sir