Monday, August 31, 2015
How to Detect Mobile Browsers (11 Steps)
Download the 'Detect Mobile User Agents & Browsers' PHP script by clicking on the link located in the 'Resources' section below. The downloaded file is compressed. Double-click on it to open your default extraction program and extract the files to your desktop.
Open an FTP (File Transfer Protocol) program and log in to your website's hosting account by typing in your FTP address, username, and password. Once you have connected to your hosting server, use the FTP program to upload the 'mobile_device_detect.php' file that you extracted in step 1. Upload it to the root directory of your website where your 'index.html' or 'index.php' file resides.
Use the FTP program to download the 'index.html' or 'index.php' file from your website and save it on your desktop. Open the file in a text editor such as Notepad or Wordpad.
Open a web browser and type 'http://detectmobilebrowsers.mobi/" into the address bar, then press the ENTER key. Alternately, you can click the 'Detect Mobile Browsers Website' link in the 'Resources' section below.
Scroll down to the 'Function Generator' heading. Here we will generate a PHP function code that will define how the PHP code file we uploaded in step 2 will behave. Choose an option from the respective drop-down menus for 'Detect iPhones,' 'Detect iPads,' 'Detect Android Devices,' 'Detect Opera Browsers,' 'Detect Blackberry Devices,' 'Detect Palm Mobiles' and 'Detect Windows Mobile Devices'. Each drop-down menu will allow you to specify whether to treat the device browser like a mobile browser or a standard desktop browser. You may also choose to redirect a device type to a custom URL, which must be typed into the text field that appears below the drop-down menu when you choose the 'Redirect (device) to a specific URL' option.
Choose an option from the 'Redirect Mobile Browsers' drop-down menu. Any devices that were set in the above options to be treated like a mobile browser will be affected by this option. You can redirect mobile users to a custom URL where there is a mobile browser-optimized version of your website or choose not to redirect them, which will allow them to access the standard website. Type the mobile-optimized website URL into the provided text box.
Set the 'Redirect Desktop Browsers' drop-down menu to 'No - Do not redirect desktop visitors - function will return false' to allow desktop browser users to access the standard website. Any devices that were set in the above options to be treated like desktop browsers will be affected by this option.
Click the 'Generate Code' button. Highlight the text that appears in the 'PHP Code' box and press CTRL+C on your keyboard to copy the text to your clipboard. Minimize your web browser so you can see the 'index.html' or 'index.php' file you opened in the text editor in step 3.
Create a blank line at the beginning of the text document by clicking your mouse at the top of the document and pressing the ENTER key. Place your cursor on the blank line and type '
' and press ENTER again.
Click on the 'File' menu at the top of the text editor and choose 'Save'. In the FTP program window, copy the edited 'index.html' or 'index.php' file back to the root directory of your website, overwriting the original file.
Access your website from a mobile device browser. You should be redirected to you mobile-optimized website. Access your website from a standard browser to make sure that you are directed to the standard website.