Here is my javascript code
<script type="text/javascript">
var country,url;
country = geoip_country_code()
if(country=="US"){
url="http://www.site.org/index.php?user=php variable";
}
setTimeout("location.href = url;",5000);
</script>
i need put $_GET['user']
php variable for get username in the current url
tried with this but not work
if(country=="US"){
url="http://www.site.org/index.php?user=<?php echo $_GET['user']; ?>";
}
You can do this in plain javascript:
var query = (function() {
var result = {}, keyValuePairs = location.search.slice(1).split('&');
keyValuePairs.forEach(function(keyValuePair) {
keyValuePair = keyValuePair.split('=');
result[keyValuePair[0]] = keyValuePair[1] || '';
});
return result;
})();
if(country=="US"){
url="http://www.site.org/index.php" + (query.user !== undefined) ? "?user=" + query.user : "";
}
See https://stackoverflow.com/a/647272/838733 for the iffy specifics.
Assuming $_GET['user']
is set:
var user = "<?php echo $_GET['user']; ?>";
url="http://www.site.org/index.php?user="+user;
This is the version using pure PHP:
$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=$_SERVER['HTTP_CLIENT_IP']";
$country = geoplugin_countryCode;
if($country=="US"){
$url="http://www.site.org/index.php?user=$_GET['user']";
}
sleep(5);
header("Location: $url");