GeoIP on Acquia Cloud with Cloud Edge (Powered by Akamai)

When developing a Drupal application on Acquia Cloud you may have the need to utilize the geographical location data and/or IP addresses of your visitors for application functionality.

In this use case we have Acquia Cloud Edge (Powered by Akamai) in front of a Drupal enterprise web application hosted on Acquia Cloud. The diagram below illustrates the workflow of using geolocation data on Acquia Cloud with Akamai in the mix. It is important to note that dedicated load balancers are required with your subscription in this scenario.

GeoIP with Cloud Edge

Image: Diagram showing GeoIP on Acquia Cloud with Cloud Edge (Powered by Akamai).

The recommended next step is for customers to enable Akamai EdgeScape at the Akamai layer. If you are using Acquia's Akamai product EdgeScape will be enabled by default for high level (i.e. country) geolocation data. If you need more granular data (i.e. city, town, county), please talk to your Acquia account manager, CSM or TAM. If you are using your company's Akamai, you will want to confirm that EdgeScape is enabled.

The final piece to the setup is a quick configuration change on the server stack at Acquia. You can talk to your TAM, CSM, or AM or file an Acquia Support ticket and request that Acquia enable a reverse proxy header on Acquia Cloud for your application. This can only be completed by Acquia Support engineers. Once this is in place you can use the header in PHP application code like the example below.

To extract the user's country using the x-akamai-edgescape header in PHP, you can use the following code or similar:

  $headerParts = explode(",", $header);
  foreach ($headerParts as $part) {
    $partParts = explode("=", $part);
    if (count($partParts) == 2 && $partParts[0] == "country_code") {
      $countryCode = $partParts[1];

This code checks if the x-akamai-edgescape header is set in the request, and then extracts the country code from the header value. The explode function is used to split the header value into its parts, and the foreach loop is used to iterate over each part to find the country_code part. Once the country_code part is found, its value is assigned to the $countryCode variable.

If you need further help, please reach out to your account team and/or Acquia Support.