Redirect if handheld device
Permalink 2 users found helpfulFirst off, I have seen the C5Touch tutorial and although fantastic (which it is), I have a project which requires actual redirection to a new C5 site designed specifically for Handheld devices.
The theme isn't the issue here, the clients wants a very small amount of reference info on the iphone version while the full site has a mountain of content.
Has anyone managed to get redirection of handheld devices to work and if so, any chance of a little help?
I am a PHP dud so please be forgiving. :-)
As I said, i am a dud at PHP, do I just drop the generated PHP code into my header.php within my themes elements folder (obviously after changing the redirect address)?
Thanks again for pointing this out.
http://www.russellbeattie.com/blog/mobile-browser-detection-in-php...
helper comes in compendium theme.
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); /* mobile browser detection byhttp://www.russellbeattie.com/blog/mobile-browser-detection-in-php... */ class AgentDetectionHelper { var $isMobile = false; var $isBot = false; var $op = strtolower($_SERVER['HTTP_X_OPERAMINI_PHONE']); var $ua = strtolower($_SERVER['HTTP_USER_AGENT']); var $ac = strtolower($_SERVER['HTTP_ACCEPT']); var $ip = $_SERVER['REMOTE_ADDR']; public static function getAgent(){ return $this->$isMobile = strpos($this->$ac, 'application/vnd.wap.xhtml+xml') !== false || $this->$op != '' || strpos($this->ua, 'sony') !== false || strpos($this->ua, 'symbian') !== false
I am also looking to perform a redirect for mobile, and this seems to be the most promising thread I found. I am pretty soft when it comes to PHP, and looking for some guidance on how to implement this code. What file(s) to I put it into, and where do I enter the URLs for redirect?
Any help at all would be greatly appreciated. Thank you!
Andrey
<?php $ah = Loader::helper('agent_detection'); $ah->getAgent(); ?>
...then further down in your template whenever you want to have something that's different for mobile, do this:
<?php if ($ah->isMobile): ?> <!--Put your mobile markup here --> <?php else: ?> <!--Put your normal markup here --> <?php endif; ?>
<?php $ah = Loader::helper('agent_detection'); $ah->getAgent(); if ($ah->isMobile) { header('Location:http://example.com'); die(); } ?>
I just tried this, and got this error when I load the page:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in [my site path] /helpers/agent_detection.php on line 12
Andrey
Andrey
Loader::library('Browser'); $browser = new Browser(); if($browser->isMobile()) { //mobile }
vars cannot have functions in them)
On Oct 8, 2011 11:09 PM, "Concrete5 Community" <discussions@concretecms.com>
wrote:
I would like to have an option on the bottom of the mobile site to 'View full site' -- however if I link it to the homepage, it will just perform the detection again and re-direct to mobile version. Is there any way around that? Thank you!
Andrey
by simply adding ?site=full or ?site=mobile it will force the webpage to display and save the selection (full or mobile)
This isn't working for me... (nor the other way around, from mobile to full). Did I implement incorrectly? I just placed the browser.php into the libraries folder to get the detection to work.
Thanks,
Andrey
Again, any help appreciated, and very thankful for your guidance so far.
Andrey
I hope you don't mind if I bug you one last time - I got everything working, including the mobile detection, and the mobile/full redirect. There's one thing I've been completely struggling with though: I would like to have the iPad go to the full version of the site, not the mobile. I've tried editing the code everywhere the ipad is mentioned in the detection file, but it still goes to mobile. Do you by any chance have any ideas on this?
Thanks for all your help,
Andrey
The parse error (~line12) was being caused by the $_SERVER('HTTP_X_OPERA_SOMETHING') not being set. I also added some additional user agents strings iphone, ipod, android ( ipad excluded ).
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class AgentDetectionHelper{ var $isMobile = false; var $isBot = false; var $op // http operamini phone ,$ua // http user agent ,$ac // http accept ,$ip // remote IP address ; function AgentDetectionHelper(){ $this->op = (isset($_SERVER['HTTP_X_OPERAMINI_PHONE'])) ? strtolower( $_SERVER['HTTP_X_OPERAMINI_PHONE']) : null; $this->ua = (isset($_SERVER['HTTP_USER_AGENT'])) ? strtolower( $_SERVER['HTTP_USER_AGENT']) : null; $this->ac = (isset($_SERVER['HTTP_ACCEPT'])) ? strtolower( $_SERVER['HTTP_ACCEPT']) : null; $this->ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : null;
... just tested and is working ...
1) Download TerWurfl from sourceforge and setup the database
2) In the root Library Folder of your C5 install put the TerWurfl folder in that folder but name it mobi (should be /library/mobi).
3) In the root Library folder add a file named theme_switcher.php and that file will be coded like so
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class ThemeSwitcher { public function mobicheck($view) { // Create sessions for full, mobile and mobile to full if ($_GET["m"] == "f") { session_start(); $_SESSION['mobi'] = 'full'; }else{ if ($_GET["m"] == "m") { session_start(); $_SESSION['mobi'] = 'mobi'; }} if ($_SESSION['mobi'] !== "full") { // Include the Tera-WURFL file require_once('mobi/TeraWurfl.php');
4) In the root config folder create a site_events.php file. The code for that will be
<?php Events::extend('on_start', 'ThemeSwitcher', 'mobicheck', 'libraries/theme_switcher.php'); ?>
5) In the site.php file add
define('ENABLE_APPLICATION_EVENTS', true);
Make sure the mobile theme(s) you want are installed (but not activated) and the script will call the theme based on what you set it to. You can do multi themes (ex iphone, PDA and/or WAP) if you want. We set up 1 wurfl database and use the same one for everyone. Much easier to update 1 database. Just make sure the TeraWurlConfig.php file has the right database info.
Hopefully this helps and hopefully I didn't forget anything. Sorry been on a 36hr code binge so if I missed something, just let me know.
I have been unsuccessful to this point, but this thread has gotten me to the point where I don't get any more errors, but the video doesn't disable.
I have asked this same question in the Support for that package, but this solution may work for other packages as well.
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $url = parse_url($videoURL); parse_str($url['query'], $query); $c = Page::getCurrentPage(); $vWidth=425; $vHeight=100; class AgentDetectionHelper{ var $isMobile = false; var $isBot = false; var $op // http operamini phone ,$ua // http user agent ,$ac // http accept ,$ip // remote IP address ;
You will want to input whatever mobile device you're coding for on this line (which is line 106 in my file)
if($isMobile='android'){
I have the same issue and im looking for a help please!
I will use a mobile site which is a summary of my regualr site for my mobile users cleints where they can directly find the needed info. So, with the mobile site's theme come already the instrucion codes to redirect it at the mobile users. So i need to insert the redirection script on my regular's root site "index.php" but i cannont find it? I want my website as thishttp://www.myC5website.com/mobile... on the mobile subdomain comes my mobile's site.
how can i do it please?
im stuck right there. Well, i don't need a responsive theme cause it's another story for what i meant.
Hope to hear from you soon
Best!
Malko
http://detectmobilebrowser.com/...
hope it helps