Skip to content

Instantly share code, notes, and snippets.

@sta1r
Created November 15, 2012 14:23
Show Gist options
  • Select an option

  • Save sta1r/4078844 to your computer and use it in GitHub Desktop.

Select an option

Save sta1r/4078844 to your computer and use it in GitHub Desktop.
GeoIP detection + conditional messaging
<?php
include($_SERVER['DOCUMENT_ROOT'].'GeoIP.inc');
$gi = geoip_open($_SERVER['DOCUMENT_ROOT'].'country.dat', GEOIP_STANDARD); // not recommended, better for server to query maintained file
$country = geoip_country_code_by_addr($gi,$_SERVER['REMOTE_ADDR']);
if (( $country == "IE")) { ?>
<h2>Welcome Irish visitors</h2>
<?php } else if (($country == "US")) { ?>
<h2>Welcome American visitors</h2>
<?php } else { ?>
<h2>Welcome visitors</h2>
<?php }
geoip_close($gi);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment