HOWTO : Mobile Subdomain Redirection Scheme

So,. you want to have a mobile site, and on it you want to have a full site button. Here is what you need to do to integrate a solution using PHP.

This can be a real pain in the ass, and after I fought with PHP Sessions not passing stuff between subdomains, and hours of server configuration changes and logs read, I can up with a cookie based method.

1) Visitors that have been redirected to your mobile site, will be given a cookie that is valid across the entire domain, by setting it to just the domainname without www. or mobile, etc…
2) If a visitor hits a page in the main site, and they don’t have the cookie, you can send them directly to the mobile site, however, if they have the cookie demonstrating that they prefer the full site, then cancel the redirection.
3) Once on your mobile site, add a page called full-site.html that will set a cookie for their preferred view, you will then be able to test against that variable in the front end main site before redirection.

Avoid a redirection loop and just update the cookies, and redirect only when it’s correct.

I personally used a custom php class to detect the devices, then php to bake/check the cookies. Pretty easy using this approach.

Tags: ,

Comments are closed.