www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 36

Thread: After Mobile Redirect - View Full Site link

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Posts
    26

    After Mobile Redirect - View Full Site link

    I have a mobile redirect that works and points to a template mobile site. Now I need to bypass that and have the option to view the "Full Site" through a link on the mobile site. I've read the best way to do this is by setting a cookie, and found a site that gives example files to do this.

    http://webservices.usc.edu/blog/deve...ile_detection/

    The example works fine on my site, but when i try to integrate this with my joomla index.php it fails and I get multiple errors.

    Has anyone successfully done this with joomla or see how this code could be integrated? Or know of a better way to approaching this? Thanks for any help.

  2. #2
    Join Date
    Aug 2006
    Posts
    1,897
    Can't help with the cookie thing, but an alternative. I pass a parameter "mode" to my main site, and in the main site index.php file, if "mode" is present and = "desktop", I don't do the mobile redirect, and go right to the main site view. If mode="mobile" I jump right to the mobile site without checking, and if mode doesn't exist, I do the redirect check and do whatever it decides. Then on the mobile site, the link to the main site looks like "index.php?mode=desktop"

    Dave

  3. #3
    Join Date
    Jun 2005
    Posts
    26
    Thanks, sounds like it could work for my setup. Do you have an example page that's using this that I could see the code your talking about? I'd really like not to use cookies if I don't have to just because people maybe not be set to accept them, so this sounds like it would be an even better solution.

  4. #4
    Join Date
    Aug 2006
    Posts
    1,897
    I don't have a page you can look at, but it's just something like this.

    Mobile site:
    Code:
    <a href="http://www.mainsite.com/?mode=desktop">Jump to full site</a>
    Main site:
    PHP Code:
    <?php
    switch($_GET['mode'])
        {
    case 
    'mobile':
        
    $mode "mobile";
        break;
    case 
    'desktop':
        
    $mode "desktop";
        break;
    default:
        
    $mode IsMobile() ? "mobile" "desktop";
        break;
        }

    if (
    $mode == "mobile")
        {
        
    header ("Location: http://www.mobilesite.com");
        return;
        }

    // rest of main site goes here
    ?>

  5. #5
    Join Date
    Jun 2005
    Posts
    26
    Thanks a lot! I'll try it out and see how it integrates with what I have setup.

  6. #6
    Join Date
    Jun 2005
    Posts
    26
    After placing that at the top of my index.php I get the following error from a normal browser.

    Fatal error: Call to undefined function: ismobile() in /nfs/c02/h07/mnt/17839/domains/mysite.com/html/index.php on line 11

    It seems like it's looking for that "mobile" or "desktop" in the link before it can go to the regular index.php

    If I go to http://mysite.com/index.php?mode=desktop it will go to the main page of my site, but then none of the links work...

    I'll keep messing with it, but if you see an easy fix let me know. This is out of my league, so I'm just trying to cut and paste what I see from other examples.

    thanks
    Last edited by xover15; 01-31-2011 at 11:49 AM.

  7. #7
    Join Date
    Aug 2006
    Posts
    1,897
    "ismobile" is the call to your mobile checker, which you said you already had. You can call it whatever you want, I just happen to call mine ismobile. It needs to return true if the client is mobile.

    Just a note... it is quite dangerous to be using code from random sources on the internet without truly knowing what it does. PHP code has the ability to do absolutely anything to your site, and if you're not thoroughly reading through and understanding it, you are placing a fair bit of faith in the source it came from. That includes code from me, by the way.

    Dave

  8. #8
    Join Date
    Jun 2005
    Posts
    26
    gotcha, thanks for the warning.

  9. #9
    Join Date
    Apr 2011
    Posts
    14
    tracknut, thanks for the code. I tried it on my mobile site and it works. But I have the same problem as xover15, when you go to main site from mobile site, page links on the main site do not work, it sends you back to the mobile site. Any idea on how to fix that?

  10. #10
    Join Date
    Aug 2006
    Posts
    1,897
    Quote Originally Posted by nailyener View Post
    Any idea on how to fix that?
    Not without seeing your code...

    Dave

  11. #11
    Join Date
    Apr 2011
    Posts
    14
    Here is the PHP code on my main site's index.php:

    Code:
    <?php
    function is_mobile(){
    	$regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
    	$regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
    	$regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";	
    	$regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
    	$regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
    	$regex_match.=")/i";		
    	return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
    }
    
    switch($_GET['mode'])
        {
    case 'mobile':
        $mode = "mobile";
        break;
    case 'desktop':
        $mode = "desktop";
        break;
    default:
        $mode = is_mobile() ? "mobile" : "desktop";
        break;
        }
    
    if ($mode == "mobile")
        {
        header ("Location: http://mobile.mainsite.com/");
        return;
        }
    ?>
    And I use

    Code:
    <a href="http://www.mainsite.com/?mode=desktop">Full Site</a>
    on the mobile site. By the way the extension of my mobile site's pages are .html

  12. #12
    Join Date
    Aug 2006
    Posts
    1,897
    And what's an example of one of the page links on the main site that inappropriately links you back to the mobile site? Is this code live somewhere we can see it?

    Dave

  13. #13
    Join Date
    Apr 2011
    Posts
    14
    Quote Originally Posted by tracknut View Post
    And what's an example of one of the page links on the main site that inappropriately links you back to the mobile site? Is this code live somewhere we can see it?

    Dave
    Surely, the site is neonstring.com and the mobile version is m.neonstring.com. The (main site) pages that don't work properly on mobile device have this parameter "?tasket=...".

    Thank you very much for your interest Dave.

  14. #14
    Join Date
    Aug 2006
    Posts
    1,897
    Can you point me to one of the specific links that fails? I'm clicking away on the links in the main (desktop) site, and haven't been redirected to the mobile site once...

    Dave

  15. #15
    Join Date
    Apr 2011
    Posts
    14
    Are you checking on a mobile device?

    neonstring.com works fine as it should on a desktop browser. When you go "neonstring.com" on a mobile device, it redirects to "m.neonstring", that's good. Then, when I click on the "Full Site" link, it redirects to "neonstring.com", that's also good. But, when I click on the "Photos", "Videos", "About Us", etc. links they redirect back to "m.neonstring", that's not good.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles