It redirects them to the bottom of this page to view as Mobile (or normal).
They click mobile.
In theory the page turns over, triggers the $cookie to find it's mobile, and then further down it sees that Cookie, and directs them appropriately.
The issue here is, it's not taking them anywhere at all. It just turns the page over and shows the same thing. And if you then click View as Mobile again, it then gives you the wrong URL.
A few questions:
1) can you set a cookie at the top and then handle things within the same PHP file?
2) if yes to (1), why would then not turn the page over to the right redirect from "mobile"?
Code: Select all
<?php
$cookie = isset($_REQUEST['cookie']) ? $_REQUEST['cookie'] : null;
if (isset($cookie))
{
if ($cookie == "mobile")
{
setcookie("site", "", time()-13600);
setcookie("site", $cookie, time()+13600);
}
if ($cookie == "normal")
{
setcookie("site", "", time()-13600);
setcookie("site", $cookie, time()+13600);
}
}
$cookiesite = isset($_COOKIE['site']) ? $_COOKIE['site'] : null;
if(isset($cookiesite))
{
if ($cookiesite == "mobile")
{
$url = $_GET['url'];
$newstring = substr_replace($url, 'm', 7, 3);
echo "<meta http-equiv='Refresh' content='0 ;URL=$newstring'>";
}
if ($cookiesite == "normal")
{
$url = $_GET['url'];
$newstring = substr_replace($url, 'www', 7, 1);
echo "<meta http-equiv='Refresh' content='0 ;URL=$newstring'>";
}
}
elseif ($cookiesite == NULL)
{
$url = $_GET['url'];
$newstring = substr_replace($url, 'm', 7, 3);
echo "<br/><br/><div style='text-align: center'><a href='http://www.site.co.uk/ip_mobilehome.php?cookie=mobile&url=$newstring'>Choose Mobile Version</a><Br/><br/>
<a href='http://www.site.co.uk/ip_mobilehome.php?cookie=normal&url=$url'>Choose Normal Version</a></div>";
}