0

I am working on a WordPress theme whose news stories are loaded in an iPhone app as well. We need the theme to detect whether the news story is being loaded from a mobile browser (chrome, safari, etc..) or from the iPhone app so we can serve a slightly different stylesheet.

Because I am mainly redesigning the existing theme, I know that the following code is responsible for completing that detection, but I can't seem to find out how/why it works:

if(isset($_GET['iphone'])) {
    //do different stuff
}

Can someone explain the $_GET['iphone'] part?

Thank you in advance!

EDIT: Basically it looks like the app simply appends ?iphone to the url is it requesting.

  • 2
    There is not nearly enough information supplied to answer this. Please provide more code. Do you know what $_GET variables are? example.com/?iphone=something – GhostToast Jan 10 '14 at 20:30
  • Ohhh, that make sense now - thanks! see my comment on the accepted answer below – Stephen S. Jan 10 '14 at 20:50
2

$_GET is for accessing variables in URL parameters, it's not related to any detection by itself, something must be adding it to URL.

In context of WordPress it might be related to $is_iphone global.

If you look at wp-includes/vars.php there is number of global variables like this, which WP fills up with data via user agent sniffing.

So $is_iphone is set there according to following logic:

if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
    $is_iphone = true;
  • Oh gosh - of course it was something so simple. It looks like the app is simply appending ?iphone to the end of the url when accessing it – Stephen S. Jan 10 '14 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.