Posted by warsteiner21 3 years 49 weeks ago
I would like to use Device Atlas to be able to detect the iPhone and then re-direct to an iPhone specific site. If the device is not an iPhone I would like to deliver the standard mobile page.
I have the following code at the top of the standard mobile page:
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; require_once 'da_api.php'; $tree = da_get_tree_from_file('json/DeviceAtlas.json'); $ua = $_SERVER['HTTP_USER_AGENT']; if(da_get_property($tree, $ua, model) == 'iPhone') { header('Location: http://mysite.mobi/iphone/'); } ?>
Is this the correct use of Device Atlas for this purpose?
Is an 'else' statement needed to deliver the standard (current) mobile page if the device is not an iPhone?
If so, what should that 'else' statement contain?
I have also found the following PHP detection/re-direction, not using Device Atlas
<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) { header('Location: http://www.expressionindesign.com/iphone/'); } ?>
Is there any disadvantage to using the 2nd method?
Any feedback would be appreciated.
Thanks




Posted by daniel.hunt 3 years ago
Mobile Grandmaster
Your PHP only solution will, of course, work at the moment. But what would happen if, in the future, the iPhone UA string changed slightly?
A change such as changing "iPhone" to "apple3rdgen" or something like that would mean yuor site would no longer work.
Admittedly, such a change is unlikely, but the reason DeviceAtlas exists is so that developers such as ourselves don't need to know anything about user agents. All we need to care about is devices. The iPhone itself will always be the iPhone :)
As for your original question, whenever you do a PHP Header Location, you must die() after it, to prevent the rest of the page from being executed.
A popular way to do this is to use a wrapper function so that you never forget:
dotMobi
Posted by warsteiner21 3 years ago
Thank you for your help Daniel.
Can you please confirm that, if the page is accessed by a device other than the iPhone, the my_redirect function will be ignored and the rest of the code will be executed?
Also, is the correct location for this code at the top of the page, above the 1st head tag, as follows:
Posted by daniel.hunt 3 years ago
Mobile Grandmaster
Sorry for the delayed response, this seems to have slipped through my net!
A quick glance tells me that what you're trying to do won't work!
If you want to do *ANY* redirecting, you cannot output any content before the Header() function is called.
Hang on while I modify your code slightly.
*edit*
That slight change should work. Also remember that the API example I've given you isn't actually the most up to date usage. The new API is written with PHP5 OO code!
Have you implemented it yet? How have you been getting on with DeviceAtlas?
Daniel Hunt
Daniel HuntdotMobi
dotMobi
Posted by abbyeagle 1 year ago
Hi Daniel, how would you modify the code to redirect from
http://www.abbyeagle.com/nlp-hypnotherapy/weight-loss.php
to
http://www.m.abbyeagle.com/nlp-hypnotherapy/weight-loss.php
Where would i enter these paths?
NLP Hypnotherapy Gold Coast