Created
November 15, 2012 14:23
-
-
Save sta1r/4078844 to your computer and use it in GitHub Desktop.
GeoIP detection + conditional messaging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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