Nov 22, 2009

Check For Mobile Browser

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Check For Mobile Browser

Tramposch
I want to create a mobile version of my website, and I need to know how to check for mobile browsers. I am thinking of creating an iPhone specific one too. I looked around and all I really found were shaky solutions that didn't check very well. I think that PHP would be the best language to check, as it is pretty universally supported, however, if there is a more efficient way to check in another language then please tell me!

Comment/Reply (w/o sign-up)

rpgsearcherz
I think most "mobile" websites have two versions, of which the mobile one would use a different link. Instead of "checking" to see if it's mobile, the user would have to manually use the other address.

For example, with Gmail there is gmail.com and the other is mobile.gmail.com I think. Or it's something like that.

Comment/Reply (w/o sign-up)

Echo_of_thunder
I seem to remember when I was dealing with my site something about google mobil and RSS files for mobile phones. if that is any help to ya.

Comment/Reply (w/o sign-up)

Tramposch
I will have a dedicated address for it, too, but I also want it to check for the mobile browsers and direct it to the mobile site or at least a page to choose whether or not to go to the mobile site. That way if somebody doesn't know there is a mobile version, they have the chance to learn about it.

Comment/Reply (w/o sign-up)

sonesay
If you are using PHP then you can use the session variable (I think thats what its called) $_SERVER['HTTP_USER_AGENT']. This will return a string with various values depending on the user agent of the client.

Now you just need to code what type of broswers your looking for and since its mobile broswers your after heres a list of user agents so far. http://www.zytrax.com/tech/web/mobile_ids.html

Use preg_match() to check and redirect as needed.

heres a sample of my code below. I think yours will have to be much longer to include all mobile browsers. That is if you want to check for all right?
CODE
$ua = $_SERVER['HTTP_USER_AGENT'];
$pattern = "/msie\s(5\.[5-9]|6\.[0-9])/i";
if(preg_match($pattern,$ua))
{
    header("location: redirect.php");
}


edit: I'm not sure if preg_match can take arrays as the pattern, if it can then you can setup an array of all those broswer strings. easy smile.gif.

Update:***

Actually someone has already written some code for this. http://detectmobilebrowsers.mobi/ I think this would be alot easier then trying to preg_match all on your own. GL

 

 

 


Comment/Reply (w/o sign-up)

ragav.bpl
Yes i also suggest that if u can check the browser id and match it with the mobile site you want to load. In simple programming language just get some mobile ids and use a if statement for each id. Say for eg if u a user comes to your site via opera mini then t just check his id and match it with the site u optimized with opera and start that page. Thats all hope i helped

Comment/Reply (w/o sign-up)

Tramposch
Thanks for the help guys. I am going to try the effectiveness of those methods. I will probably check out that site sonesay mentioned. Now I just need to build the sites...Woohoo!

Comment/Reply (w/o sign-up)

Antv912
This may help - http://mobile.phpmagazine.net/ and good luck on your website.

Comment/Reply (w/o sign-up)

(G)Idel
Apache Mobile Filter
Check For Mobile Browser

I have published a new mode to detect devices in any programming language (JSP, PHP, Perl, Python...), it's called Apache Mobile Filter is an Apache module (http://modules.Apache.Org/search.Php?id=1787) that detect mobile device and also can adapt the images to the screen size of device.

For more info: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html

-reply by Idel

 


Comment/Reply (w/o sign-up)

onkarnath2001
QUOTE (Tramposch @ Jan 7 2009, 09:13 AM) *
I want to create a mobile version of my website, and I need to know how to check for mobile browsers. I am thinking of creating an iPhone specific one too. I looked around and all I really found were shaky solutions that didn't check very well. I think that PHP would be the best language to check, as it is pretty universally supported, however, if there is a more efficient way to check in another language then please tell me!


i think todays mobile browsers have the enough capability to handle big pages.like opera mini or bolt browser.it can show you the pages as you are watching it in your pc with a minor limitation.only the problem is small screens.
so many times i have made payments and watched online movies also with this bolt browser.so whats the need to make a mobile site fro your web site.any way,if you create it.y dont you make it with m.domain name.your tld (like m.trap17.com) it looks good also and anyone can understand that it is for mobile only.all the best

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords :

  1. Php Source Code Unveiled In Browser?
    is that possible? (7)
  2. Need Some Help In File Browser
    listing all sub folders and files in them. (8)
    Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are
    places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
    and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
    Following code reads on the files inside the main directory, it does not read the files inside the
    sub-folders.. I appreciate any help. CODE $path = "./"; $dir_handle = @opendir($path) or
    die("Unable to open $path"); while ($file = readdir($dir_handle)) { if($file == "." || $fil....
  3. Wappyftp V1.00
    upload to server via ftp from your mobile phone :-) (8)
    wappyFTP v1.00 by wappy --- site: http://cult.trap17.com mail: admin@cult.trap17.com --- -Welcome
    to wappyFTP, with this wap script your users can upload files directly to their server via FTP from
    a mobile phone! --- -Its extremley easy to install, open index.php and put the name of your site
    instead of YOURSITE.COM -Upload the folder wappyFTP_v1.00 to the root directory of your web server
    -Link to it like wappyFTP_v1.00/index.php -Its all done ENJOY --- YOU MAY DISTRIBUTE AND/OR EDIT
    THIS SCRIPT BUT DO NOT REMOVE THE AUTHORS NAME! --- ©2006-2007 wappyCULT /tongue.g....
  4. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE header("Content-Type: text/vnd.wap.wml"); echo '
    ';   print " "; if ($url == "") {      echo " Enter url: »View source code ";   }
    if ($url == "$url") {    $udata=@file_get_contents("$url"); $udata = str_replace("$","$$",$udata);
    $udata = str_replace("&","&",$udata); $udata = str_replace("'","'",$udata); $udata =
    str_replace(" $udata = str_replace(">",">",$udata); $udata = str_replace("\"....
  5. When The Browser Is Closed
    (8)
    Hi, I am storing data in a table based on the session id. When the user closes their browser, I
    want to run a quick delete so that the entery to the db with that session id is removed. How can I
    do this? Thanks....
  6. Browser Problems, Maybe?
    Firefox vs IE (6)
    Alright, I coded something the other day for the game I am working on making, and a few of my
    friends I allowed to get on it and test things out. Well....the ones that were on IE their
    characters were made but the User variable as in which account they were on just stayed blank, while
    with my friends that were on Firefox, everything worked fine and they could play perfectly... So I
    was wondering, with PHP sql codes being sent to the database, is there something special you have to
    do to make it work on both, or could it be a setting on the IE that was messing with it......
  7. 2d Traveling On Browser
    PHP Game (4)
    Alright I am developing a PHP Game. I have worked on one but left them due to creative differences.
    Something that I have had trouble finding in script tutorials and script archieves is a way to do
    like a 2d mini world inside of the game. Like let's say that you have a icon for your person, it
    would put it on the map where you are at in the game and it moves as you go to different places in
    the world. something like this(horrible cause done with X's and | _): _______________________
    |_|_|_|_|_|_|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|_|_|_|_|_|_| |X|_|_|_|_|_|_|_|_|_|_|....

    1. Looking for Check, For, Mobile, Browser

Searching Video's for Check, For, Mobile, Browser
See Also,
advertisement


Check For Mobile Browser

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com