Qustion about 'web browser' identification (mobile)

Discussion in 'PHP' started by standard240, Sep 30, 2007.

  1. standard240

    standard240 New Member

    Sep 30, 2007
    Likes Received:
    Trophy Points:
    I was wondering if anyone could tell me how exactly a website knows if you are visiting from your computer (ie/firefox) or from your cell phone browser???

    For example, if I go to http://mobile.google.com in firefox, it is a different webpage than if I use my mobile browser.

    I just need to know how it works, or how I can access the mobile version of a webpage on my PC?

    Any info will help!
  2. shabbir

    shabbir Administrator Staff Member

    Jul 12, 2004
    Likes Received:
    Trophy Points:
    It totally depends on how the web site owner has setup his website. Lets say you are a site owner and when you detect a mobile web browser you redirect them to page a and when its PC user you redirect them to page b. Now by no means when you are at your PC you can view the page a because it will redirect you to page b and vice versa.

    Now I think there should be a way to fool the coding out there but for that you should be doing some RnD.

    First have a website page where you can get the details about your mobile page like browser type / OS. Now using the Firefox browser agent have your details as if you are on mobile and try browsing the website using that agent and you may have some success but I am not sure about it.
  3. pete_bisby

    pete_bisby New Member

    Nov 11, 2007
    Likes Received:
    Trophy Points:
    Software Developer/Analyst, PB
    Manchester, England
    Home Page:
    Use the phpinfo() function to return all of the variables associated with PHP. Towards the end of the page that has loaded within your web browser you will see the _SERVER variables. One of these variables, _SERVER["HTTP_USER_AGENT"], will return the description of the web browser you are using (I've omitted the dollar sign in front of the _SERVER, just in case it plays havoc with the forum !!)

    As a quick test, using IE6, the server variable returns "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; www.lifetranslator.biz; InfoPath.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)".

    Using Firefox returns "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv: Gecko/20071025 Firefox/".

    (tested on Windows XP Professional platform, using Apache Web Server)

    Now if you create a simple index.php page and use a switch statement looking for specific information within the _SERVER["HTTP_USER_AGENT"] variable, you will be able to redirect web browsers on different platforms to the correct code pages.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice