0

I am redesigning a site and I want to have it compatible with the IPad. Could someone show me the code in either JavaScript or PHP so that when someone comes to my site on an IPad they will be automatically redirected to a site that is narrower, contains no Flash graphics and the navigation system does not use mouseover flyouts?

Apple provides this useragent code:

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

The code I need is to detect the IPad and then redirect the user to another webpage.
Thanks

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by smantscheff
0

The following construct does the redirect:

if (preg_match( '~iPad;~', $_SERVER['HTTP_REFERER'])) {
  header( "Location: http://$mySpecialIpadSite" );
  exit;
}

Refine the preg expression and substitute your site for $mySpecialIpadSite.

Edited by smantscheff: n/a

0

Sorry to have to ask, but I don't understand the refinement to the preg_match function.
I tried this:

<?php
  if (preg_match( '~iPad~;', $_SERVER['HTTP_REFERER'])) {
      header( "Location: http://www.rspsiotedesign.com/test.html" );
      exit;
       }
?
and this:
<?php
  if (preg_match( '\iPad\;', $_SERVER['HTTP_REFERER'])) {
      header( "Location: http://www.mysite.com/test.html" );
      exit;
       }

with no luck. Would appreciate the help. Thanks
?

0

Learn about preg regular expressions.
Your regular expressions are malformed.
Learn about debugging. Configure your server or your script (with error_reporting(E_ALL) so that it gives you the appropriate error message Warning: preg_match() [function.preg-match]: Unknown modifier ';' in x.php on line y As long as you search for exact strings only, you better use strpos instead of preg_match.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.