Point them to Mobile site - how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Point them to Mobile site - how?

Post by simonmlewis »

Hi
I am after a bit of advice.
We have a web site that uses a PHP preg_match script to determine if they are on iphone, blackberry or android (yes I know there are others). And if they are, it redirects them straight to the mobile version.

However, we want to give them the option to "go to Normal site" should they want to, since many phones now show the normal site just as well - and often it has more features anyway.

Code: Select all

if ((preg_match("/(iPhone|BlackBerry|Android)/", $_SERVER["HTTP_USER_AGENT"]) || ($cookiedevice == NULL))
{   ... }
I did this would work with the extra bit on the end - so they'd go to the mobile site, and click to use normal site. That would then store a $cookie saying "normalbrowser" for example, and as such that cookie is no longer NULL, and it keeps them on the normal site.

But this won't work, because it's an "||" or statement. So what's the best way to do this?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Point them to Mobile site - how?

Post by requinix »

You've correctly identified that a || will not work for this. What else could you use instead?
Post Reply