FYI, im using Joomla CMS as my website platform
I want to redirect my visitor to different website based on their respective country. (GeoIP)
malaysia -> www.myweb.com/my
thailand -> www.myweb.com/th
indonesia -> www.myweb.com/id
In order to do so, i'm trying to use "session" function to detect my visitor country so that the can be be redirected to correct website.
My testing script as below.
index.php
CODE
<?php
session_start();
$ip = $_SERVER['REMOTE_ADDR'];
$url = "http://www.geoplugin.net/xml.gp?ip=".$ip;
$xml = simplexml_load_file($url);
//echo $xml->geoplugin_countryName;
$country= $xml->geoplugin_countryName;
if ($country == "Malaysia") {
echo ' MY:<br>';
echo $country;
echo '<br>';
$_SESSION["country"] = $country;
echo $_SESSION["country"];
?>
<script type="text/javascript">
window.location = "page.php";
</script>
<?php
elseif ($ctr == "Thailand") {
echo ' thailand';
}
else {
echo $xml->geoplugin_countryName;
}
?>
This is the output for index.php
MY:
Malaysia
Malaysia
However, when the page has been redirected to page.php, the "session' has return NULL (blank) value. Please advise
page.html
CODE
<?php
session_start();
echo 'test script';
echo $_SESSION["chk"];
?>
Perhaps is there any other solution for this problem?