/    Sign up×
Community /Pin to ProfileBookmark

auto redirect for blackberries?

Hi everyone. I’m just looking for a redirect, an if-then-else type of thing I can put on a PHP page that will tell if the user is using a mobile device – i.e. Blackberry, iPhone and maybe a few others – and redirect them to my mobile site. I’m trying to find a server-side solution because Blackberries don’t read javascript. I’ve seen some partial & generic examples already, but I was hoping someone had or knew of some script that was ready to go.

I don’t need to include an exhaustive list of user agents or anything – I’m just trying to catch the most common mobile devices. If some go through to the regular site, it’s no big deal, I’ll have a button there, plus a javascript command to catch any iPhones. If I can get, like, 75% of mobile devices I’ll be happy.

Can anyone help? PHP total newbie here, in case it wasn’t obvious already. Thanks so much, and looking forward to your responses.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Learning_curveauthorJan 26.2010 — Thanks - I think that will get me most of the way there. One last question - I need to include an 'else' condition that will direct non-mobile browsers to the default (main) website. The page this code would go on is not the main page - it would just be a dummy/sorter page. The main website is not a PHP page at all and in fact is on a different server. So anyway, what is the correct placement and syntax for inserting an 'else' statement in that code that would take care of the default redirect? Once I have that, I think I'm good. Thanks so much for your help!
Copy linkTweet thisAlerts:
@SrWebDeveloperJan 26.2010 — If you mean Mindzai's code in reply #6 of that thread....

Old Code:

[code=php]if(checkmobile()) header('Location:http://www.yourmobilepage.com/');
[/code]


New Code:

[code=php]if(checkmobile()) {
header('Location:http://www.yourmobilepage.com/');
}
else {
header('Location:http://www.yourdomain.com/main_page');
}[/code]


On a side note (unrelated to the solution posted above) you might want to put this line before each header line ---it helps with SEO:

header("HTTP/1.1 301 Moved Permanently");

-jim
×

Success!

Help @Learning_curve spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...