Jump to content


Photo
* * * * * 1 votes

how to: Add Detection and Auto-redirection for other smartphones


  • Please log in to reply
4 replies to this topic

#1 mcreedy

mcreedy

    Member

  • Members
  • PipPip
  • 42 posts

Posted 31 May 2011 - 09:38 AM

Currently, the iPhone / Mobile Module only supports detection and auto-redirection to the mobile site for the iPhone/iPod.

If you want Detection and Auto-redirection for other smartphones......HTC, Sony Ericsson, Nokia, Opera and Android.....here is the code.

Edit /include/config.php from your server

- Find: require $config['BASE_DIR']. '/include/security.php';

- Add right above it:

//Added for HTC Detection and Auto-redirection
$config['HTC'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['HTC'] = strpos($_SERVER['HTTP_USER_AGENT'],"HTC");
if($config['HTC']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for Blackberry Detection and Auto-redirection
$config['BLACKBERRY'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['BLACKBERRY'] = strpos($_SERVER['HTTP_USER_AGENT'],"Blackberry");
if($config['BLACKBERRY']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for Nokia Detection and Auto-redirection
$config['NOKIA'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['NOKIA'] = strpos($_SERVER['HTTP_USER_AGENT'],"Nokia");
if($config['NOKIA']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for SonyEricsson Detection and Auto-redirection
$config['SONYERICSSON'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['SONYERICSSON'] = strpos($_SERVER['HTTP_USER_AGENT'],"SonyEricsson");
if($config['SONYERICSSON']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for Opera Mobi Detection and Auto-redirection
$config['OPERAMOBI'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['OPERAMOBI'] = strpos($_SERVER['HTTP_USER_AGENT'],"Opera Mobi");
if($config['OPERAMOBI']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for Opera Mini Detection and Auto-redirection
$config['OPERAMINI'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['OPERAMINI'] = strpos($_SERVER['HTTP_USER_AGENT'],"Opera Mini");
if($config['OPERAMINI']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for Android Detection and Auto-redirection
$config['ANDROID'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['ANDROID'] = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
if($config['ANDROID']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

//Added for Palm Detection and Auto-redirection
$config['PALM'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['PALM'] = strpos($_SERVER['HTTP_USER_AGENT'],"Palm");
if($config['PALM']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

I have tested auto detection and redirection on HTC and it works well.
I cant test auto detection and redirection on the other smartphones listed above as I don't have the smart phone to test it on, but the auto detection and redirection should work all the same as the HTTP_USER_AGENT are correctly defined.

#2 twisted

twisted

    Junior Member

  • Members
  • Pip
  • 12 posts

Posted 31 July 2012 - 05:50 AM

this code is awesome, can you write something to make it work on the iPad?

#3 sextube

sextube

    Senior Member

  • Members
  • PipPipPipPip
  • 242 posts

Posted 23 October 2012 - 12:11 AM

Nice addition, it detects my android mobile but not my android tablet

My user agent on my adroid tablet seems to be iPad:

//Added for iPad Detection and Auto-redirection
$config['PALM'] = '';
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['BASE_URL'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['iPad'] = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
if($config['iPad']){
if(!defined('_MOBILE') && !defined('_ADMIN')){
VRedirect::go($config['MOBILE_URL']);}}}

seems to work for me :)

Edited by sextube, 23 October 2012 - 01:29 AM.


#4 dargre

dargre

    Senior Member

  • Members
  • PipPipPipPipPip
  • 991 posts

Posted 23 October 2012 - 10:17 PM

Nice addition, it detects my android mobile but not my android tablet
seems to work for me :)


if this is sextube.dk domain, I'm afraid it doesn't work under iphone,ipad, also under androids I can access.
Suggested is to use some universal detection class (there is few good classes around) to detect device correctly. Additionally it would be good to have html5 player or html5 fallbeck javascript detection to be 100% sure so videos will play, even if mobile template not loaded.

VIDEO.JS - best HTML5 player in the world for AVS script

NUEVOPLAYER 8 - best flash+html5 player for video scripts
Mods, custom code by NuevoLab (Search Suggest, Multiple image upload, Seo mods,and much more)


#5 apple82

apple82

    Member

  • Members
  • PipPipPipPip
  • 300 posts
  • LocationSpain

Posted 28 May 2013 - 05:24 PM

Thanks!!!!