How to implement Mobile browser detection?

Discussion in 'PHP' started by mcfox, Oct 20, 2010.

  1. #1
    mcfox, Oct 20, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    I guess you just put the code below into a common file, say a config file for example or at the top of the php pages you want to detect a mobile on and then upload your generated file from that site. The generated file, will determine what actions to do if its a mobile, eg: redirect to a mobile equivalent page etc..

    require_once('mobile_device_detect.php');
    $mobile = mobile_device_detect();
    PHP:
     
    MyVodaFone, Oct 20, 2010 IP
    mcfox likes this.
  3. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #3
    And that can be implemented on an existing website? By that I mean redirecting to a mobile version of an existing website.

    Sorry for the noob questions but I've been consistently avoiding anything to do with mobiles but finally decided to have a crack at it.
     
    mcfox, Oct 20, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Correct... just for testing etc.. assuming you have a configuration file "config.php" place the above code into that, and for testing until you create mobile friendly pages, redirect to google.com or place the code into a test file test.php. Its the generated file from that site that will do all the work, its basically just looking for mobile browsers useragents and performers your predefined actions set in the generated file for the different mobile types.
     
    MyVodaFone, Oct 20, 2010 IP
  5. morency

    morency Well-Known Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #5
    
    require_once('mobile_device_detect.php');
    mobile_device_detect(true,true,true,true,true,true,true,'http://mymobilesiteORmobilepage.com','http://mypcsiteORpcpage.com');
    
    
    PHP:
    :)
     
    morency, Oct 21, 2010 IP
  6. flight05

    flight05 Active Member

    Messages:
    122
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #6
    Thats what I would guess, I could help implement it for you.
     
    flight05, Oct 22, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    I believe the author of that site/script is a user here (can't remember the username) perhaps if you search the relevant threads where that url is recalled you'll spot the user...and you can then get in touch.

    I'd assume you'd simply include the core function file and then do a function call, theirfore add the code morency kindly mentioned at the top of a global php file (such as a config?) or wherever you'd like the mobile detection to occur - changing the two urls accordingly (self explanatory which is for what)
     
    Last edited: Oct 22, 2010
    danx10, Oct 22, 2010 IP
  8. AnoxiA

    AnoxiA Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You should look at PHP BrowserCap:
    http://github.com/garetjax/phpbrowscap
    made my life really easy at some projects, it might help you with Mobile Browser Detection.
     
    AnoxiA, Oct 22, 2010 IP
  9. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #9
    Thanks. Looks pretty straightforward. :)

    I had a look as you suggested and he is indeed a member here. Have you seen this? Awesome! I can't believe nobody even commented.
     
    mcfox, Oct 23, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    I would'nt say its awesome as I've seen a few other scripts which do very similar functionality (and free) so not original, but admit its useful.
     
    danx10, Oct 23, 2010 IP