iPhone redirect?

Discussion in 'Jailbreaks and iOS Hacks' started by BevvyB, Jul 5, 2007.

  1. BevvyB macrumors member

    Joined:
    Jun 3, 2003
    #1
    Is there a way to have your site spot an iPhone and redirect accordingly?
    ALSO
    Has anyone created a 'basic iPhone template' out there to get started for the less technical of us - html and css
    Cheers
    B
     
  2. voidptr macrumors regular

    Joined:
    Jan 11, 2007
    #2
    Query the user agent header in the request for the iPhone's browser. (iPhone; U; CPU like Mac OS X; en)

    http://developer.apple.com/iphone/

    If you're doing QT, use a container movie to point to separate desktop, WiFi, and EDGE versions.
     
  3. Daremo macrumors 68000

    Daremo

    Joined:
    Jul 3, 2007
    Location:
    Chicago
    #3
    I'm pulling my hair out trying to figure this out too. Is there a way you can write out the script for us newbies?

    I have looked all over, and come up empty. Basically, when the iPhone surfs to my site, it automatically redirects to my iPhone formatted page instead. I build my sites in GoLive, so I'm not as good with code.

    Help!
     
  4. codyc1515 macrumors member

    Joined:
    Dec 31, 2008
    #4
    Some custom code and iWebkit

    Code I use to redirect is quite simple, although requires php:
    PHP:
    <?php
    // Powered by www.codynz.com

    if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE)
    {
    header("Location: /thelocationofthemobilewebsite/");}

    else if (
    strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE)
    {
    header("Location: /thelocationofthemobilewebsite/");}
    ?>
    and visit http://www.iwebkit.net for the iPhone customised website templates.
     
  5. ppc750fx macrumors 65816

    Joined:
    Aug 20, 2008
    #5
    ...

    Simpler option:

    PHP:
    <?php

    // Screw licenses.  This is too trivial.  Use this code any way you want.

    define('MOBILE_SITE_URL''http://example.com/m');
    if(
    strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE ||
       
    strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE) {
        
        
    header("Location: " MOBILE_SITE_URL);    
    }

    ?>
     
  6. codyc1515 macrumors member

    Joined:
    Dec 31, 2008
    #6
    Even Simpler

    Look ive made it even simpler:

    PHP:
    <?php
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE) {
    header("Location: /locationofmobilesite/");    }
    ?>
     
  7. ppc750fx macrumors 65816

    Joined:
    Aug 20, 2008
    #7
    Yes, but using constants for strings is considered good practice... ;)
     
  8. Spooner83 macrumors regular

    Spooner83

    Joined:
    Jan 31, 2011
    #8
    I understand that I put my site address where it says to but what do I put where it says user agent?
     

Share This Page