I need a domain example.com redirects to sub-domain a.example.com when I type on the address bar.
<script type="text/javascript">
$(function(){
var city = readCookie('city');
if(city==null && city==''){
window.location.href = 'http://' + city + '.example.com';
}
$('#citygo').change(function(){
var city = $(this).val();
createCookie('city', city, 28);
window.location.href = 'http://' + city + '.example.com';
});
});
</script>
<body>
<select id="citygo">
<option value="0">Select City</option>
<option value="amsterdam">Amsterdam</option>
<option value="newyork">New York</option>
<option value="london">London</option>
<option value="cardiff">Cardiff</option>
</select>
</body>
The cookie on the server side is not holding so the domain cannot remember sub-domain. What am i doing wrong? Any help will be very much appreciated.
<?php
$hour = time() + 50400;
setcookie(My_Site_Location, $_POST['citygo'], $hour);
$Loc=$_COOKIE["city"];
if(isset($_POST['city']))
$Loc=$_POST['city'];
if (empty($Loc)) {
header("Location: http://{$_COOKIE["city"]}.example.com");
} else {
header("Location: example.com/$Loc.php");
}
?>