After lots of headbanging, spitting and cussing, this is what I did to get device detection working on my one of my sites (namebook.mobi).
This tutorial is really basic and its geared towards beginners. There may be better ways, but this is what worked for me:
Please take all the standard precautions, like backing up your files ect...
Download Andy Moores script here:
http://www.andymoore.info/php-to-detect-mobile-phones/
Unzip the file (theres only one) and its called php-to-detect-mobile-phones.php
After you have unzipped this file, you can open it with a regular text editor such as windows notepad.
Edit the script with your site information. Its towards the bottom of the script. I have used my site namebook.mobi as an example.
// example 1 - detect and redirect mobile browsers
if(detect_mobile_device()){
header('Location: http://namebook.mobi/mobile/');
exit;
}
// example 2 - detect and redirect desktop browsers
if(!detect_mobile_device()){
header('Location: http://namebook.mobi/pc/');
exit;
Save the edited file and then rename it to: index.php
You then need to access your server with an FTP program (I use Smart ftp).
Navigate to the site directory that you want to have device detection on (for example: namebook.mobi).
In this directory create two new folders. Name one of the folders mobile and the other one call it pc.
You will need to copy all your site directory files into the mobile folder and then also copy them into the pc folder.
Next, delete your main site files (because you just copied them into the two other folders).
You do not need to delete robots.txt, .htaccess, cgi-bin, or .ftpquota. Just the unnecessary site files. If you are not sure - ask!
Next upload Andy Moores device detection script (index.php) to your site directory.
For instance: I uploaded it to my namebook directory.
Here is whats in my namebook directory now:
a folder called mobile (contains all my mobile site files)
a folder called pc (contains all my pc site files)
a file called index.php (the device dectection script)
a file called cgi-bin
a file called .ftpquota
a file called .htaccess
a file called robots.txt
Now comes the fun part. You can go into your mobile folder and edit your site for proper mobile viewing and then open your pc folder and edit its site files for proper pc viewing. This may include editing your .css files and adsense code which is beyond the scope of this tut.
If you have done everything properly it should work!
Bookmarks