Last active
September 22, 2016 15:03
-
-
Save drAlberT/ab0609918302f3a4161b465810e38efd to your computer and use it in GitHub Desktop.
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 | |
define('FORCE_HTTPS', true); //set true if you want only https | |
//@see https://github.com/maxmind/geoip-api-php | |
define('GI_INCLUDE_PATH', __DIR__.'/includes/geoip'); | |
require_once GI_INCLUDE_PATH.'/geoip.inc.php'; | |
//XXX to be improved | |
$languages = array('en', 'it', 'de'); //first is default | |
$proto = 'http'; | |
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { | |
$_SERVER['HTTPS'] = 'on'; | |
$_SERVER['SERVER_PORT'] = 443; | |
$proto='https'; | |
} | |
if ( FORCE_HTTPS || isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ) { | |
$proto='https'; | |
} | |
$ip = ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && ''!=$_SERVER['HTTP_X_FORWARDED_FOR'] ) | |
? strtok($_SERVER["HTTP_X_FORWARDED_FOR"], ',') | |
: $_SERVER['REMOTE_ADDR']; | |
$gi = geoip_open(GI_INCLUDE_PATH.'/GeoIP.dat', GEOIP_STANDARD); | |
$country_code = geoip_country_code_by_addr($gi, $ip); | |
geoip_close($gi); | |
switch($country_code) { | |
case 'IT': | |
$store_id = 'it'; | |
break; | |
case 'DE': | |
case 'AT': | |
$store_id = 'de'; | |
break; | |
default: | |
$store_id = 'en'; | |
break; | |
} | |
$url_fmt = sprintf('%s://%s/%%s/', $proto, getenv('HTTP_HOST')); | |
foreach ($languages as $k => $lang) { | |
$languages[$lang] = sprintf($url_fmt, $lang); | |
unset($languages[$k]); | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<meta name="description" content="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" /> | |
<meta name="keywords" content="" /> | |
<meta name="robots" content="NOINDEX,FOLLOW" /> | |
<meta name="author" content="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" /> | |
<link rel="icon" href="/favicon.ico" type="image/x-icon" /> | |
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> | |
<title>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</title> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'auto'); | |
ga('send', 'pageview'); | |
//]]> | |
</script> | |
<script type="text/javascript" src="<?php echo $proto; ?>://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(window).load(function(){ | |
window.location = "<?php echo $languages[$store_id] ?>"; | |
}); | |
</script> | |
</head> | |
<body class="page-empty"> | |
<noscript> | |
<h1>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</h1> | |
<div class="global-site-notice noscript"> | |
<div class="notice-inner"> | |
<p> | |
<strong>JavaScript seems to be disabled in your browser.</strong><br> | |
You must have JavaScript enabled in your browser to utilize the functionality of this website. | |
</p> | |
</div> | |
</div> | |
<ul> | |
<?php | |
foreach ( $languages as $lang => $url) { | |
printf(" <li><a href=\"%s\">%s</a></li>\n", $url, $url); | |
} | |
?> | |
</ul> | |
</noscript> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment