Jump to content


Photo

Smartphones and Pocket PCs redirection


  • Please log in to reply
8 replies to this topic

#1 segri

segri

    Etomite Forum Newbie

  • Member
  • 3 posts

Posted 07 April 2009 - 06:33 PM

Hi, everybody,
Please, would any of PHP experts help me to accomplish this script and verify if everything is correct in it, or not. I'm not a programmer, but I need to create a new snippet to redirect those who use pocket pcs and smartphones to a special page based on a template that fits common mobile browsers requirements. The script is to define user's OS.

<?
$redirect_uri = "_http://www.anysite.org/smartphones.php";

if (eregi("(windows ce)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}"))

elseif (eregi("(palmos) ([0-9]{1,2}.[0-9]{1,2}){0,1}"))

elseif (eregi("symbian"))

elseif (eregi("nitro"))

elseif (eregi("maemo"))

elseif (eregi("PLAYSTATION"))

elseif (eregi("j2me/midp"))

{
Header ("Location: $redirect_uri");
}
?>

#2 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,106 posts

Posted 07 April 2009 - 08:22 PM

You will need to detect the browser by using $_REQUEST['HTTP_USER_AGENT'] or other methods for phone browsers.

Also, for the redirect, use $etomite->sendRedirect($redirect_uri);

I'm not sure about the ereg, it's really not my cup of tea, but if it works go for it.

You might like to have a look at this example...
http://www.russellbe...etection-in-php

Edited by Cris D., 07 April 2009 - 08:30 PM.


#3 segri

segri

    Etomite Forum Newbie

  • Member
  • 3 posts

Posted 07 April 2009 - 08:55 PM

You will need to detect the browser by using $_REQUEST['HTTP_USER_AGENT'] or other methods for phone browsers.

Also, for the redirect, use $etomite->sendRedirect($redirect_uri);

I'm not sure about the ereg, it's really not my cup of tea, but if it works go for it.

You might like to have a look at this example...
http://www.russellbe...etection-in-php


Thank you, Cris, but before I click the link you suggested, there's another idea of the code:
how about it?

<?php
if (stripos($_SERVER['HTTP_USER_AGENT'], 'windows ce') !== FALSE) // or == TRUE
elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'palmos') !== FALSE) // or == TRUE
elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'symbian') !== FALSE) // or == TRUE
elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'nitro') !== FALSE) // or == TRUE
elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'maemo') !== FALSE) // or == TRUE
elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'PLAYSTATION') !== FALSE) // or == TRUE
else if (stripos($_SERVER['HTTP_USER_AGENT'], 'j2me/midp') !== FALSE) // or == TRUE

{
Header ("Location: _http://www.anysite.org/smartphones.php");
}
else
{
Header ("Location: _http://www.anysite.org/index.php");
}
?>

Thus we can chop off all possible mobile OSs and render user a proper page.

#4 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,106 posts

Posted 08 April 2009 - 04:07 AM

Why do I get the funny feeling that you are not listening?

$etomite->sendRedirect();
And why ask for more help on 1/2 baked code when you havn't checked out the resource I reccomended?

No-one is going to help you unless you have at least tried the code above and can explain the results. Did you want me to install this and test it for you and make the changes and post it back?... It's not going to happen.

I won't be replying to this thread again unless it looks like you are actually trying to integrate it within an etomite installation and can quote the parser error.

#5 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 08 April 2009 - 01:29 PM

CrisD is right, segri...

We're here to give you the best advice we can without having to do all of the work ourselves as we have plenty of our own to do... If someone supplies you with links to code, whether proven or unproven, take advantage of the searching they have already done for you first... If that code can't be adapted, then we can go from there... Remember, you are venturing into what is virgin territory for many of us... I still use tree-knocking for communications... :lol:

As far as using $etomite->sendRedirect() instead of header(), the reasoning behind this is that sendRedirect() has features and error handling the header() doesn't have... Whevener Etomite has an alternative to a standard PHP function there is usually a reason and you should use the Etomite alternative...

#6 segri

segri

    Etomite Forum Newbie

  • Member
  • 3 posts

Posted 09 April 2009 - 08:17 AM

Sure nobody has to do anything for me. I just wanted some hints from PHP programmers to know for the future if I'm on the right way with the code. Currently my Etomite is running on my Localhost for the purpose of creating nice templates and trying all it's features with other cool snippets. So I can't yet test redirection with my pocket PC. As soon as I put my pages on the net, I'll certainly report all the problems I encounter.

Edited by segri, 09 April 2009 - 08:20 AM.


#7 Dean

Dean

    Loves Etomite Forums!

  • Admin
  • 4,790 posts

Posted 09 April 2009 - 08:53 AM

Be sure to let us know how you get on!!

#8 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 09 April 2009 - 12:49 PM

I use DTDNS on my home/office network because static IP's are too expensive... There are several very simple updater clients for Windows machines... I've been using DTDNS for what seems like forever...

#9 thebowes

thebowes

    Etomite Forum Newbie

  • Member
  • 1 posts

Posted 28 June 2009 - 07:03 AM

Help,

I am trying to put redirection code into my website for mobile users as our pages will not shrink, i have created a basic infomation page to redirect mobile users to, i just need some code that works and yes i am thick, where in the HTML code do i place it. etc.

Thank you for your help

thebowes




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users