×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    25

    redirecting users / detecting browser/ phone model type

    Does anyone know how to detect which browser a user is using in php? I have found plenty of asp code for this:
    http://www.ehonline.com/archives/HA0108DIY.htm
    http://www.wirelessdevnet.com/channels/wap/expert/

    ...but I need to do it in php (linux hosting).

    I can redirect them to html or wml (detecting a mobile browser):
    http://allnetdevices.com/faq/?pair=04.006

    ...but I can't redirect them to the appropriate wml file (i.e. a nokia file for nokia users and another file for up.browser users). Seen as though up.browser is more popular than nokia browser I'll have to just use the up.browser until nokia figure out a way to fix this problem.

    anyone any ideas...?

    thanks.

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    334
    Hello!

    One way is to put additional if-statement to the code e.g.:

    ...
    if($br == "WML") {
    if($browser=="Noki") {
    header("302 Moved Temporarily"); // Force the browser to load the Nokia WML file instead
    header("Location: ".$wmlredirect_toNokia);
    exit;
    }
    if($browser=="UP.B") {
    header("302 Moved Temporarily"); // Force the browser to load the UP Browser WML file instead
    header("Location: ".$wmlredirect_toUP);
    exit;
    }
    }
    ...

    and define $wmlredirect_toUP and $wmlredirect_toNokia variables for terminal specific pages.



    Kind regards,

    sami / Forum Nokia Developer Support

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    25

    detecting users wap browser/redirecting to wml / html file

    Thanks for you reply. I've been working on it and added it to my code below to redirect users to the approriate file, but my code below only works for html redirect and not for wml.

    ............................
    <?
    $htmlredirect = "/web/index.html";
    $wmlredirect_toUPB = "http://www.mysite.com/upb/index.wml";
    $wmlredirect_toNOK = "http://www.mysite.com/nokia/index.wml";

    if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) {
    $br = "WML";
    }
    else {
    $browser=substr(trim($HTTP_USER_AGENT),0,4);
    if($browser=="Noki" ||
    $browser=="Eric" ||
    $browser=="WapI" ||
    $browser=="MC21" ||
    $browser=="AUR " ||
    $browser=="R380" ||
    $browser=="UP.B" ||
    $browser=="WinW" ||
    $browser=="UPG1" ||
    $browser=="QWAP" ||
    $browser=="Jigs" ||
    $browser=="Java" ||
    $browser=="Alca" ||
    $browser=="Wapa")
    {
    $br = "WML";
    }
    else {
    $br = "HTML";
    }
    }
    if($br == "WML") {
    if($browser=="Noki") {
    header("302 Moved Temporarily");
    header("Location: ".$wmlredirect_toNOK);
    exit;
    }
    if($browser=="UP.B") {
    header("302 Moved Temporarily");
    header("Location: ".$wmlredirect_toUPB);
    exit;
    }
    }
    else {
    header("302 Moved Temporarily");
    header("Location: ".$htmlredirect);
    exit;
    }
    ?>

    ...................
    my url's are ok, my files on my server are ok, but the redirection still doesn't work to my wml files.

    There's probably a simple mistake in their somewhere, but I don't know what it is. Anyone any ideas?

  4. #4
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    334
    Hello!

    If the MIME type vnd.wap.wml is found from the HTTP_ACCEPT header the $browser variable is not set at all and redirect if-statements are not true.

    You can try to move code line:

    $browser=substr(trim($HTTP_USER_AGENT),0,4);

    before the very first if-statement so that $browser variable is always set.


    Kind regards,

    sami / Forum Nokia Developer Support

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    25

    redirecting wap browsers

    Thanks for your help - it now works ok! The main problem was with the emulators - their browser can't be detected (maybe this is normal) anyway a real nokia phone is redirected ok.


    For anyone who is interested the full code is below. it was split into two - the first to detect wml or html then a second php script was used to detect if a nokia browser was being used - if it wasn't users are directed towards the up browser instead.

    ...............................................................
    index.php in the root folder

    1 detecting wml or html (if it detects wml it goes to index.php in the wml folder)

    <?

    $htmlredirect = "/web/index.html";
    $wmlredirect = "http://www.mysite.com/wml/index.php";

    if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) {
    $br = "WML";
    }
    else {
    $browser=substr(trim($HTTP_USER_AGENT),0,4);
    if($browser=="Noki" ||
    $browser=="Eric" ||
    $browser=="WapI" ||
    $browser=="MC21" ||
    $browser=="AUR " ||
    $browser=="R380" ||
    $browser=="UP.B" ||
    $browser=="WinW" ||
    $browser=="UPG1" ||
    $browser=="upsi" ||
    $browser=="QWAP" ||
    $browser=="Jigs" ||
    $browser=="Java" ||
    $browser=="Alca" ||
    $browser=="MITS" ||
    $browser=="MOT-" ||
    $browser=="My S" ||
    $browser=="WAPJ" ||
    $browser=="fetc" ||
    $browser=="ALAV" ||
    $browser=="Wapa")
    {
    $br = "WML";
    }
    else {
    $br = "HTML";
    }
    }
    if($br == "WML") {
    header("302 Moved Temporarily");
    header("Location: ".$wmlredirect);
    exit;
    }
    else {
    header("302 Moved Temporarily");
    header("Location: ".$htmlredirect);
    exit;
    }
    ?>


    ......................................
    index.php file located in the wml folder

    2 detecting nokia browser else - going to upbrowser file:

    <?
    $UPB_redirect = "http://www.mysite.com/wml/upb/index.wml";
    $NOK_redirect = "http://www.mysite.com/wml/nokia/index.wml";

    $browser=substr(trim($HTTP_USER_AGENT),0,4);

    if($browser=="Noki") {
    header("302 Moved Temporarily");
    header("Location: ".$NOK_redirect);
    exit;
    }
    else {
    header("302 Moved Temporarily");
    header("Location: ".$UPB_redirect);
    exit;
    }
    ?>
    ................................................

    tip for newcommers - check it on a real phone (dodgy results with emulators) not sure if its possible to work with emulators.

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    Thanks...but...

    Ok..Thanks for this, It was a great help for a newbie like me.
    I allready managed the first part of that script by myself (cut & paste from the net) and the second part was just what i needed.
    Thanks again for that. (thanks for asking, bramsley)

    But what about detecting different phone types?
    Is there a php script like the one above that can detect a 6100 etc?

    Please let me know.

    Flashone
    Last edited by thierrywendriks; 2003-12-29 at 17:44.

  7. #7
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    almost complete

    This is what i got so far:

    <?
    $UPB_redirect = "http://domain/wap/wrong_phone_detected.php";
    $NOK6100_redirect = "http://www.domain/wap/6100.wml";

    //$phone_type = $_SERVER['HTTP_USER_AGENT'];
    $phone_type = substr(trim($HTTP_USER_AGENT),0,9);

    //if($phone_type=="Nokia6100/1.0 (05.16) Profile/MIDP-1.0 Configuration/CLDC-1.0") {
    if($phone_type=="Nokia6100") {
    header("302 Moved Temporarily");
    header("Location: ".$NOK6100_redirect);
    exit;
    }
    else {
    header("302 Moved Temporarily");
    header("Location: ".$UPB_redirect);
    exit;
    }
    ?>


    No problem with it, it works fine.
    but there's one problem: it only filters out nokia 6100 (or any other type i fill in) and i want it to redirect 7250 phones to 7250.wml 6100 phones to 6100 wml and unknown phonetypes to unknown.wml etc etc.

    Can someone please help me with that?
    I don't need to know the user agents only how i can let the script redirect more phones at the same time. (not only one)

    xcuse me for the bad english.

    Thanks.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    1

    Re: redirecting users / detecting browser/ phone model type

    Php script to redirect it is easy to redirect or continue the same page with script above but with some little changes:
    remove last part of script that contain html page redirect script with a "continue" instruction or just a variable to prevent redundant loop if you want to continue same page (it is important for SEO optimization to begin index page with fully text page).

    Script with changes is bellow:

    <?php

    $htmlredirect = "/web/index.html";
    $wmlredirect = "http://www.mysite.com/wml/index.php";

    if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) {
    $br = "WML";
    }
    else {
    $browser=substr(trim($HTTP_USER_AGENT),0,4);
    if($browser=="Noki" ||
    $browser=="Eric" ||
    $browser=="WapI" ||
    $browser=="MC21" ||
    $browser=="AUR " ||
    $browser=="R380" ||
    $browser=="UP.B" ||
    $browser=="WinW" ||
    $browser=="UPG1" ||
    $browser=="upsi" ||
    $browser=="QWAP" ||
    $browser=="Jigs" ||
    $browser=="Java" ||
    $browser=="Alca" ||
    $browser=="MITS" ||
    $browser=="MOT-" ||
    $browser=="My S" ||
    $browser=="WAPJ" ||
    $browser=="fetc" ||
    $browser=="ALAV" ||
    $browser=="Wapa")
    {
    $br = "WML";
    }
    else {
    $br = "HTML";
    }
    }
    if($br == "WML") {
    header("302 Moved Temporarily");
    header("Location: ".$wmlredirect);
    exit;
    }
    else {
    $problem = false;
    }
    ?>

    You have to remove condition "exit;" and headers and replace with "$problem = false;" let say.
    Then just put in your index page .php this script as first code.
    An functional example, with phone browser redirect, you can see at: www.selectquotes.net

  9. #9
    Registered User
    Join Date
    Sep 2008
    Posts
    1

    Re: redirecting users / detecting browser/ phone model type

    you could also get php code from handsetdetection.com site

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×