php redirect to mobi site - Post ID...

User 133269 Photo


Registered User
2,900 posts

from the new program suggestions thread...
cayucostom wrote:
Cheryl Davidson wrote:
I am adding my vote for a mobile website designer. The code is available for redirecting mobile browsers to mobile pages -- it helps to know a little php to use it though. I have not yet figured it out. The code can be found at http://detectmobilebrowsers.mobi/


The PHP code is here but it would be great if someone in the forums with the necessary expertise would outline exactly how to use PHP with VSD or the CCHTML Editor. For example how to call if from HTML What exactly needs to be in the PHP and where to locate the PHP on the server. Where is Fe Pixie when we need her?
Cayucostom


righto - now bad news all you VSD users - the first step of getting php code to go in your page is to save the file the code will go in as a .php file - and thats going to mess up VSD.... so - move along to the html editor...

I havent downloaded an investigated your script there Cheryl - i've just written a short example script for you...

to make ANY php go in your page - it has to be saved with a .php extension - so if you are goin to put your mobi redirect on your index page - first rename it from index.html to index.php (being renamed as a php file wont affect any of your html in the page - that will still run just the same)

once you've saved as a .php page - we need to insert some php...
this needs to go at the very top of your page - BEFORE any of the other code... (including the opening doctype tag even) Nothing at all should be before the code - not even a blank line

it needs to go up there because we dont want to output anything before we call a redirect to a mobi format page if they're using a mobi device...


<?
$ua = $_SERVER['HTTP_USER_AGENT'];

if (
stristr($ua, "Windows CE") or
stristr($ua, "AvantGo") or
stristr($ua, "Mobile") or
stristr($ua,"Syncalot") or
stristr($ua,"Mazingo") or
stristr($ua, "T68") or
stristr($ua, "Blazer") ) {
$device="MOBILE";
}
if (isset($device) and $device=="MOBILE") {
$location='mobile/index.php';
header ('Location: '.$location);
exit;
}
?>


Yup - thats it...

the line that says
$location='mobile/index.php';
can be changed to aim at the page you have made for mobi devices

the script asks the server what useragent the visitor is using (which browser)
checks if its in its list of mobi browsers
and if it is - it redirects to a different page

there are lots and lots of other useragents that are used by mobile devices. This script will catch and redirect a lot of them, but not all. And more are added all the time.

You can find more info about all the different mobi ua's here:
http://wurfl.sourceforge.net/

enjoy :)
Have fun
~ Fe Pixie ~
User 414501 Photo


Registered User
564 posts

Just FYI, I just found out that Wordpress site are automatically configured to work with mobile devices. I just made my first two web sites FULLY powered by Wordpress and was AMAZED when I pulled them up on my Blackberry and they looked and worked PERFECTLY, and automatically resized to fit the screen on my Blackberry. Sorry if this is slightly off topic for this thread, I know it's supposed to be about PHP redirects...
Chad Spillars
"Look I finally made myself a signature!"
User 467042 Photo


Registered User
19 posts

Fe Pixie,

I've logged on because of the need to get my site mobile phone friendly, and so glad to find this message.
I'm now a bit nervous but from post and all confused.

I created my site in VSD, so if I use the html section of the program I do this?

- create a mobi friendly page
- put the php code in as above
my html page stays the same
and hopefully mobile phone users will see that one page and anyone else gets the full site.

Has anyone tried this and succeeded??

A very nervous/confused VSD

www.moveclinics.com


Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.