Page 1 of 2 12 LastLast
Results 1 to 30 of 47

Thread: Auto-detecting PC/Mobile and then Redirecting

  1. #1
    Administrator Andres Kello's Avatar
    Join Date
    Jun 2007
    Location
    Barcelona
    Posts
    3,548

    Arrow Auto-detecting PC/Mobile and then Redirecting

    1. Create two folders in your server called "mobile" and "pc", each containing the respective versions of your site.
    2. Copy the code below.
    3. Replace the red links with your Mobile and PC destinations.
    4. Save and upload as your index.php
    Code:
    <?php
    
    $mobile_browser = '0';
    
    if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',
        strtolower($_SERVER['HTTP_USER_AGENT']))){
        $mobile_browser++;
        }
    
    if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or 
        ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
        $mobile_browser++;
        }
    
    $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
    $mobile_agents = array(
        'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
        'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
        'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
        'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
        'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
        'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
        'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
        'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
        'wapr','webc','winw','winw','xda','xda-');
    
    if(in_array($mobile_ua,$mobile_agents)){
        $mobile_browser++;
        }
    if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
        $mobile_browser++;
        }
    if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
        $mobile_browser=0;
        }
    
    
    if($mobile_browser>0){
       header('Location: http://YourSite.mobi/mobile');
       } else {
       header('Location: http://YourSite.mobi/pc');
       }
       
    ?>
    More info.



    ALTERNATIVES:


    My .mobi's: Dating.mobi | Dubai.mobi | Adult.mobi | Banking.mobi | Student.mobi | Call.mobi | Horoscope.mobi | Messenger.mobi | Classifieds.mobi | LiveTV.mobi

    Developed: Yup.mobi | Mobility
    | Why .mobi? | Banking | Vuelos | Airline Complaints | Random Site | Whois | Free Mobile Dating | Free Dictionary | Free Thesaurus | Horoscope | Astrology | Free Translation | Exchange Rates


  2. #2
    Senior Member gogo's Avatar
    Join Date
    Oct 2007
    Location
    planet Gogon - M25 class planet
    Posts
    3,452

    Default

    Just wondering, what if the CSS is set to be different for a "handheld" device - would you then skip WURFL?

    eg look at this: http://www.accessifyforum.com/viewtopic.php?p=54286

    and http://www.w3.org/TR/REC-CSS2/media.html

  3. #3
    MobiEnthusiast coast's Avatar
    Join Date
    Jul 2007
    Posts
    4,720

    Default

    Andres, do you have a "for dummies" version of the readmefirst.txt? I'm not a php person so I don't know how to edit the address. Thanks.
    Need a developer? MobileSiteStore.com | More good stuff at Drosty.com
    Accepting Quality guest posts via PM only for mobiEnthusiast.mobi
    (NO press releases or story ideas, completed, unique articles only
    )

  4. #4
    Administrator Andres Kello's Avatar
    Join Date
    Jun 2007
    Location
    Barcelona
    Posts
    3,548

    Default

    Quote Originally Posted by gogo View Post
    Just wondering, what if the CSS is set to be different for a "handheld" device - would you then skip WURFL?
    WURFL is used to auto-detect what device your visitor is accessing your site with and then showing them the appropriate version/format for that device. I believe you can't use CSS to do such an auto-detect so you would still require WURFL even if you use a mobile CSS stylesheet for your mobile users.

    Quote Originally Posted by coast
    Andres, do you have a "for dummies" version of the readmefirst.txt? I'm not a php person so I don't know how to edit the address. Thanks.
    Just open the file with any text-editor (e.g. Notepad) and you'll see where you have to edit the address (it's pretty simple and self-explanatory once you view it in the editor). If you have any more questions, just post here.
    My .mobi's: Dating.mobi | Dubai.mobi | Adult.mobi | Banking.mobi | Student.mobi | Call.mobi | Horoscope.mobi | Messenger.mobi | Classifieds.mobi | LiveTV.mobi

    Developed: Yup.mobi | Mobility
    | Why .mobi? | Banking | Vuelos | Airline Complaints | Random Site | Whois | Free Mobile Dating | Free Dictionary | Free Thesaurus | Horoscope | Astrology | Free Translation | Exchange Rates


  5. #5
    Senior Member GijsZePa's Avatar
    Join Date
    Jul 2007
    Location
    Nieuw-Vennep, The Netherlands
    Posts
    2,799

    Default

    Quote Originally Posted by Andres View Post
    Hi guys,

    Since I'm not a professional developer, this is something I struggled with a bit at first. To make it easy for those of you who aren't professional developers either, I've created a WURFL zipped file that contains everything you need, and makes it incredibly easy, for your .mobi site to detect whether the visitor is on a PC or a Mobile and to redirect accordingly.

    Simply download the WURFL.zip file below, extract the files, open readmefirst.txt, and follow the 5 simple steps. Couldn't be easier!



    If you have any problems, post here and we'll sort it out.

    Cheers,
    Andres
    Thanx Andres,

    But if I rename the php files to aspx it doesn't work anymore



    Martin

  6. #6
    Founding Member Scandiman's Avatar
    Join Date
    Jun 2007
    Location
    NorCal
    Posts
    9,538

    Default

    Quote Originally Posted by GijsZePa View Post
    Thanx Andres,

    But if I rename the php files to aspx it doesn't work anymore



    Martin
    Two different coding languages Martin. That won't work. That's like putting the title "English Dictionary" on a Spanish dictionary. Everyone is confused.

  7. #7
    Senior Member newton's Avatar
    Join Date
    Jun 2007
    Location
    Near a golf course
    Posts
    1,711

    Default

    Excellent thanks Andres Will try it out later in the week and will be interesting to see the differences between this one and the one I have been using since Oct 06.
    The speed of light is faster than sound that's why some people appear bright until they open their mouths

    To everyone who thinks a profitable viral marketing campaign is so easy to accomplish I would suggest to go and do it instead of complaining that others aren't - Scandiman

  8. #8
    New Member
    Join Date
    Dec 2007
    Posts
    18

    Default

    Hi u all! As a *very frecuent* user of the wurfl, I'd like to do a clarification about its usage: its not a desktop/mobile detection system, it's a mobile device capabilities identification system. Of course it could do that (a web patch exists ;-), but according to the developers, its on early stages. The major issue is that many (and I mean MANY) devices lie about their "mobility". So u cant rely on wurfl for doing device detection (a header acceptance script in php of the mime types could be more effective, and then, u apply the wurfl, in order to deliver tailored content "on demand") If u believe in the current euristhics of the wurlf, u might have some problems, coz there are around many "lying" user agents, not to mention our main menace in development mobile stuff: transcoding of pages! (specialy bad when when u do "device detection") My two cents! PS: BTW... WURLF *ABSOLUTLY* ROCKS!!! (in a world -mobile web- that nobody shares a single dime... theres an alternative that gaves all of us the chance of serving tailored contents "on demand"... how cool is that! )

  9. #9
    Senior Member GijsZePa's Avatar
    Join Date
    Jul 2007
    Location
    Nieuw-Vennep, The Netherlands
    Posts
    2,799

    Default

    Quote Originally Posted by Scandiman View Post
    Two different coding languages Martin. That won't work. That's like putting the title "English Dictionary" on a Spanish dictionary. Everyone is confused.
    oh my god...just stumbled upon your reply....well..probably need a sarcasm smiley next time ...

    There goes my credibility as developer hahaha...

    Martin
    <signature police forced me to remove my image that was too large and had nothing to do with a mobi site >


    Autodisk.mobi - all dutch carspecs | Manage all your holiday accommodations with our online manager.

  10. #10
    Founding Member Scandiman's Avatar
    Join Date
    Jun 2007
    Location
    NorCal
    Posts
    9,538

    Default

    Quote Originally Posted by GijsZePa View Post
    oh my god...just stumbled upon your reply....well..probably need a sarcasm smiley next time ...

    There goes my credibility as developer hahaha...

    Martin
    I knew you knew better, but for the benefit of others it needed explaining.

  11. #11
    Mobility Regular texasgamer's Avatar
    Join Date
    Jun 2007
    Location
    Corpus Christi Texas
    Posts
    276

    Default

    Can someone help me out on Wurfl? I know its supposed to be easy but....

    Editing the Mobile Address and the PC Address:
    note: I do not use index.xhtml for my mobi sites, but instead use index.php

    Is this the correct way to edit the address for www.namebook.mobi?:

    <?php
    require_once('/wurfl/wurfl_config.php');
    require_once(WURFL_CLASS_FILE);
    $wurflObj = new wurfl_class();
    $wurflObj->GetDeviceCapabilitiesFromAgent($_SERVER["HTTP_USER_AGENT"]);
    if ( $wurflObj->getDeviceCapability('is_wireless_device') ) {
    // Your Mobile Address
    header("Location: http://namebook.mobil");
    } else {
    // Your PC Address
    header("Location: http://namebook.mobi");
    }
    ?>

  12. #12

    Default Thanks for this Valuable information.

    I was able to ***er this solution for a company I am currently working for that has both a WAP page, (soon to be a WAP .mobi page), and a .com site. They were looking for a solution for auto redirecting and I knew the answer was posted here in this forum.

    Thanks so much for posting this Andres. My hat is *** to you. Because of this post I was able to shine today.

    We have not implemented the code as of yet, I am a little concerned of Gabriels comment. I was wondering exactly what we have to do with the MIME types?

    Julie
    New Kid on the Block - 123ask.mobi 123get.info 123get.mobi - Stay tuned!

  13. #13
    Administrator Andres Kello's Avatar
    Join Date
    Jun 2007
    Location
    Barcelona
    Posts
    3,548

    Default

    Sorry for the late responses folks, I'm only seeing these posts now.

    Quote Originally Posted by Gabriel
    Hi u all! As a *very frecuent* user of the wurfl, I'd like to do a clarification about its usage: its not a desktop/mobile detection system, it's a mobile device capabilities identification system.
    Although WURFL was created as a mobile device capabilities identification system, it can also be used to detect PC users and redirect accordingly, which is what I provided in the download. If you (or anyone) know of a better and easier way of doing that, please let us know.

    Quote Originally Posted by texasgamer View Post
    Can someone help me out on Wurfl? I know its supposed to be easy but....

    Editing the Mobile Address and the PC Address:
    note: I do not use index.xhtml for my mobi sites, but instead use index.php

    Is this the correct way to edit the address for www.namebook.mobi?:

    <?php
    require_once('/wurfl/wurfl_config.php');
    require_once(WURFL_CLASS_FILE);
    $wurflObj = new wurfl_class();
    $wurflObj->GetDeviceCapabilitiesFromAgent($_SERVER["HTTP_USER_AGENT"]);
    if ( $wurflObj->getDeviceCapability('is_wireless_device') ) {
    // Your Mobile Address
    header("Location: http://namebook.mobil");
    } else {
    // Your PC Address
    header("Location: http://namebook.mobi");
    }
    ?>
    You have edited the addresses correctly, but it seems like you are sending both PC and Mobile users to the same address which defeats the purpose of using WURFL. Ideally, you would want to redirect your PC users to a "pc" subdomain or other PC-optimized version of your site.

    Quote Originally Posted by Julie
    We have not implemented the code as of yet, I am a little concerned of Gabriels comment. I was wondering exactly what we have to do with the MIME types?
    This is not my area of expertise so I'm not sure, but this download will auto-detect PC users and redirect accordingly, so I can confirm that it does indeed work as-is.
    My .mobi's: Dating.mobi | Dubai.mobi | Adult.mobi | Banking.mobi | Student.mobi | Call.mobi | Horoscope.mobi | Messenger.mobi | Classifieds.mobi | LiveTV.mobi

    Developed: Yup.mobi | Mobility
    | Why .mobi? | Banking | Vuelos | Airline Complaints | Random Site | Whois | Free Mobile Dating | Free Dictionary | Free Thesaurus | Horoscope | Astrology | Free Translation | Exchange Rates


  14. #14
    Mobility Member
    Join Date
    Apr 2008
    Posts
    69

    Default

    -
    Last edited by asidana; 06-06-2008 at 02:04 PM.

  15. #15
    Mobility Regular texasgamer's Avatar
    Join Date
    Jun 2007
    Location
    Corpus Christi Texas
    Posts
    276

    Default

    Lightweight device-detection in PHP
    (A lightweight alternative to using DeviceAtlas or Wurfl)

    http://dev.mobi/article/lightweight-...-detection-php

    I am going to experiment with this.

  16. #16
    Mobility Regular texasgamer's Avatar
    Join Date
    Jun 2007
    Location
    Corpus Christi Texas
    Posts
    276

    Default

    I have been pulling my hair out trying to get Wurfl to work on my sites. I am posting this in hopes of helping anyone else out that is running into problems installing Wurfl.

    The first problem I ran into was from the instructions in the readmefirst.txt file.

    1) Open index.php
    2) Edit the Mobile Address and the PC Address.
    3) Save and upload all files and directories to the main directory of your server.
    4) Assign chmod 777 permission to the "data" directory (and its subdirectories) located within the "wurfl" directory.
    5) Run the update_cache.php file from your browser (located at http://yoursite/wurfl/data/update_cache.php).
    Following these instructions, I could not get Wurfl to update.
    What I eventually figured out (after beating my head for weeks) is that the Number 5 instruction appears to be wrong. I think it should read:
    5) Run the update_cache.php file from your browser (located at http://yoursite/wurfl/update_cache.php).

    In the file I downloaded from Andre, the update_cache.php file was located in the wurfl folder and not the data folder, so the update would never work correctly. After I change the path, it worked correctly!

    After a successful Wurfl update you should see a message like this in your browser:

    Parser load time:0.010666131973267
    Parsing time:6.2261588573456
    Total:1183602354.1569

  17. #17
    Senior Member developmy.mobi's Avatar
    Join Date
    Aug 2007
    Location
    Western Mass
    Posts
    1,115

    Default

    I had to change the paths that are in the script, and change require, to include.

    Then it worked for me, but for some phone browsers it would show the web version.. wurfl is of no use to me anymore.

  18. #18
    Not a member
    Join Date
    Jun 2007
    Location
    Asunción
    Posts
    130

    Default

    Hello to all,

    Since I have a bit of experience doing this, I will share my toughs:

    Problem:
    DeviceAtlas and WURFL are not the best way of detecting if a browser is Mobile or PC, because all Mobile Phones that use Windows Mobile are using Internet Explorer 7. So when a person is using Internet Explorer 7 from a PC, they are going to be redirected to your Mobile Version of the site, and viceversa.

    Solution:
    What you can do is to use an alternative way of detecting users through the User Agent string, like Andy Moore does it here: http://www.andymoore.info/php-to-detect-mobile-phones/

    Or you can put a link on your site that says if you are using Internet Explorer 7 click here to Go to PC Version and use a given parameter to disable redirection for that user.

    If you still want to use WURFL or DeviceAtlas, I will post a tutorial and some easy code in PHP5 for everyone to use.

    Hope someone find this usefull, because I know that that problem can be frustrated...

    Best regards to all,

  19. #19
    New Member TheGateKeeper's Avatar
    Join Date
    Oct 2008
    Posts
    2

    Smile My Question IS??

    Would placing this coding work with all kinds of software? I am just a mere begginer in the world of community management systems

  20. #20
    New Member
    Join Date
    Oct 2008
    Location
    Oneida, NY, USA
    Posts
    18

    Default

    Quote Originally Posted by TheGateKeeper View Post
    Would placing this coding work with all kinds of software? I am just a mere begginer in the world of community management systems
    "all kinds" is a vast kind. Maybe many many, but unlikely all, hehe.

    Actually the base WURFL PHP code and the suggested test file (README) are a bit out of sync. It uses vars that apparently no longer exist in the WURFL class.

    WURFL is good for finding a lot of information about the mobile browser.. Now numerous versions of IE look like mobile too, since some mobile devices actually use IE (higher end devices). Funnier yet though, from my experience, FF and Safari are even more likely to look like IE than IE itself (from a WURFL point of view)

    Personally I'm working on something with less overhead that still uses the WURFL for it's data (though a subset). For now I just want to know the browser window size and max image width.. And that it's mobile. If mobile, pure XHTML-MP or BASIC/WML1 depending on a fw parameters from the WURFL/UAPROF, and beyond that I don't need to know at what temperature in the freezer sends an SMS to the cell which then explodes due to an overheating freezer retaliation for not calling the maytag dude in the first place.... My freezer doesnt have a SNMP MIB or other telemetry, let alone any sort of connection (beyond the 60Hz buz if real close to the motor)...

    What's everyone else doing these days to identify the User Agent?

    -setjmp

  21. #21
    First time poster!
    Join Date
    May 2009
    Posts
    1

    Default

    Hey, i've tried adding the code to my homepage, but all it does is load up a blank page.

    am i doing something wrong?

  22. #22
    New Member
    Join Date
    Apr 2009
    Posts
    11

    Default

    Quote Originally Posted by alex5857 View Post
    Hey, i've tried adding the code to my homepage, but all it does is load up a blank page.

    am i doing something wrong?
    try to put the code before the header or at the very top of your code
    something like this:
    Code:
    <?php
    redirector snippet
    ?>
    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <!-- rest of your code -->

  23. #23
    New Member
    Join Date
    May 2009
    Posts
    3

    Default Apache Mobile Filter 2.0

    Hi,
    I suggest to look this open source project:

    http://www.idelfuschini.it/apache-mo...ilter-v2x.html

    this apache filter give you the informations of device capability as variable environment.
    So in PHP you can use for example with this syntax:

    $_SERVER['AMF_MAX_IMAGE_HEIGHT'];

    have the max_image_height capability.

    Idel

  24. #24
    New Member
    Join Date
    Nov 2009
    Posts
    2

    Default

    Hello guys!!

    I a new at mobile world. I was wondering how do wap.getjar.com is being able to show the device that is using the site at the top of the website!! like it detect the phone model as well like Nokia N95 etc..... I want to put same in my mobile site...can any one help me!!!

  25. #25

  26. #26
    New Member
    Join Date
    Nov 2009
    Posts
    2

    Default

    i cudnot understand it clearly there!! can you help me!!

  27. #27
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Default

    there is a user agent header included with all mobile browsers (native) and some downloadable mobile browsers such as operamini and opera mobile.

    Quoting the example based on who we use, the web service from handsetdetection.com detects this agent and then refer to the database to match up the appropriate device.

    Once the device is detected, they then return details of the device back to us including location, make, model, screen size, capabilities etc - which we then use in deciding what web content to display back to them.

    In actual fact, it is not a complex service - what is critical is in how up-to-date their database is, and how quick the service responds to each request.

    Google "handset detection" - all the providers come up...

  28. #28
    New Member
    Join Date
    May 2009
    Posts
    3

    Default Apache Mobile Filter is your answer

    Quote Originally Posted by avinass View Post
    Hello guys!!

    I a new at mobile world. I was wondering how do wap.getjar.com is being able to show the device that is using the site at the top of the website!! like it detect the phone model as well like Nokia N95 etc..... I want to put same in my mobile site...can any one help me!!!
    Hi Avinass I think the answer of yor question is "Apache Mobile Filter" the simple way to build a mobile site.

  29. #29
    New Member
    Join Date
    Jan 2010
    Posts
    2

    Default looks a great site

    Hi
    I'm new to this site it looks great.
    I have installed Auto-detecting PC/Mobile and then Redirecting script works great in firefox, getting an error in internet explorer 8
    if($mobile_browser>0){
    header(’Location: //metromobile’);(this is line 39)
    } else {
    header(’Location: //metrofull’);
    }
    I have deleted http on links
    metromobile & metrofull are the 2 folders as instructed
    its say syntax error in line 39
    any ideas


  30. #30
    Mobility Member firemax's Avatar
    Join Date
    Jan 2010
    Location
    Colombo/SL
    Posts
    50

    Default

    Try

    if($mobile_browser>0){
    header(’Location: metromobile’);
    } else {
    header(’Location: metrofull’);
    }



Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
A Yup.mobi Mobile Site
Barcelona Walking Tours
Mobile Dating