I'm not familiar with PHP session variables or how they work exactly, but I'm working on a site that has a mobile counterpart. On the mobile site (developed by another company)there's a link to go to the full site that uses a URL ending in '?mobile=false', and I'm just wondering how I can use that to allow mobile users to access the full site?
-
Your question is not clear. What do you mean by 'how I can use that to allow mobile users to access the full site?'? What is 'access'?CodeCaster– CodeCaster2012-04-25 09:53:26 +00:00Commented Apr 25, 2012 at 9:53
-
Access as in the ability to view the full site by clicking a link within the mobile site.sowasred2012– sowasred20122012-04-25 10:04:05 +00:00Commented Apr 25, 2012 at 10:04
-
Are those two different sites? Or is it the same site using a different template?CodeCaster– CodeCaster2012-04-25 10:04:52 +00:00Commented Apr 25, 2012 at 10:04
-
It's two different sites - using the code you suggested has done the trick!sowasred2012– sowasred20122012-04-25 10:06:27 +00:00Commented Apr 25, 2012 at 10:06
5 Answers
Put something like this in your entry point:
if (isset($_GET['mobile']) && $_GET['mobile'] == 'false')
{
session_start(); // If you haven't done so already
$_SESSION['ShowFullSite'] = true;
}
Then you can check for $_SESSION['ShowFullSite'] afterwards, which will be set as long as the session lives.
Comments
i think you shoould use the Cookies like annother development, not Session. Click Here for the documentation.
Comments
you can get the parameter using $_GET['mobile'] in the first page and set the session variable in that page and you use it in other pages. To set the session you need to start the session first. session_start(); Then to set $_SESSION['mobile']=false; You can check in pages by if($_SESSION['mobile']){ } To clear session you can use session_unset();
Comments
If I understood, you have two different sites, then if you want to redirect your users, you have to add something like this in the index of your mobile site:
if (isset($_GET['mobile']) && $_GET['mobile'] == 'false'))
header('Location: http://www.myfullsite.com/');