Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to detect if a URL has an iPhone optimized version?
Old 10-29-2010, 09:38 AM How to detect if a URL has an iPhone optimized version?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
So of course a human can easily check each URL on his/her iPhone and see if the destination is iPhone optimized or not.
But is there a machine driven way to find out?

Is there anyway of programming PHP to find out if a given URL submitted by a user
possesses an iphone optimized version of the site?

I mean a lot of sites use an iPhone dedicated conditional style sheet,
something like this:

Code:
<link media="only screen and (max-device-width: 480px)" href="http://www.randomsite.com/iphone.css" type="text/css" rel="stylesheet" />
other sites will use an Apache .htaccess redirect to a dedicated domain or subdomain based on the user agent like this

Code:
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^[\./](.*)$ http://beta.mydomain.no/iphone
or even JavaScript like this

Code:
<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   location.replace("http://url-to-send-them/iphone.html");
}
-->
</script>
I can't think of any?
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 10-29-2010 at 09:39 AM..
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-29-2010, 12:29 PM Re: How to detect if a URL has an iPhone optimized version?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
If you have cURL installed, the easiest thing to do is set your user-agent to be the same as the iPhone, request the URL, then compare the results against the same page without the user-agent set.

http://php.net/manual/en/book.curl.php

If the redirect is being done with JavaScript this won't work of course.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 10-29-2010 at 12:30 PM..
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-29-2010, 12:44 PM Re: How to detect if a URL has an iPhone optimized version?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I can't really think of a solution other than what Abel described, however I think you should take into consideration that this is a relatively expensive operation; the script would have to wait for a response from the remote server twice. This is acceptable if you only need to do a one time, or once in a while, check.

Also, comparing the results to see if they are different is not a trivial problem. The response might be different on every request, regardless of the user-agent. You'd have to know what to look for in order to definitively determine that the site is specifically serving mobile content.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-29-2010, 01:07 PM Re: How to detect if a URL has an iPhone optimized version?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Also, comparing the results to see if they are different is not a trivial problem. The response might be different on every request, regardless of the user-agent.
This is definitely true, and something I did consider. The best you may be able to do is that if they don't match, you flag the URL in your database as a possible mobile site, and then have a human confirm it.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-29-2010, 01:12 PM Re: How to detect if a URL has an iPhone optimized version?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
This is definitely true, and something I did consider. The best you may be able to do is that if they don't match, you flag the URL in your database as a possible mobile site, and then have a human confirm it.
Although, with cURL, you can set it not to follow an HTTP 301 or 302 redirect. If I remember right, you can set it to just read the header response and not the body. If you get a Location: header that is different than without sending a mobile user-agent header from your PHP script, it is trying to support mobile, in theory.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-29-2010, 07:00 PM Re: How to detect if a URL has an iPhone optimized version?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
Although, with cURL, you can set it not to follow an HTTP 301 or 302 redirect. If I remember right, you can set it to just read the header response and not the body. If you get a Location: header that is different than without sending a mobile user-agent header from your PHP script, it is trying to support mobile, in theory.

Is it possible to somehow "read" what CSS characteristics a page is serving up?

Regardless of the root to getting there, if the page contained

some commonly used Mobile Safari CSS properties

that would be a pretty big give away wouldnt it?

So if you could change the user agent using cURL to mimic an iPhone
device and then somehow parse the CSS I think that would be 90% of problem solved. No?

Easier said than done of course.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 10-29-2010 at 07:11 PM..
TWD is offline
Reply With Quote
View Public Profile
 
Old 10-30-2010, 10:51 AM Re: How to detect if a URL has an iPhone optimized version?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
It would take a little work to scrape out every possible CSS location (link, import, style tags, inline), but if you just eliminate inline it wouldn't be too bad. You'd just have to parse the HTML document to find the correct styles or locations. However, it seems to me detecting iPhone styles may not be very reliable. After all, in the case of a relatively simple site, it may just be a matter of making the whole site smaller or less complex.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to How to detect if a URL has an iPhone optimized version?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.71349 seconds with 12 queries