Mobile Device Detection/Redirection

21 views
Skip to first unread message

Henry Versemann

unread,
May 22, 2013, 6:04:41 PM5/22/13
to dot...@googlegroups.com

I’m sending this now to try and get an answer, on this, as soon as possible.

 

We have tried to write our own mobile detection logic, with some input from others, but so far what we’ve tried either has not worked at all or has not worked consistently. The code for our latest attempt is shown here:

 

http://pastebin.com/3Gt6x3Z9

 

Our main site is at www.stchas.edu while our mobile site, on a mobile host(which I’m assuming means it’s also on a different host), is at http://m.stchas.edu . The logic  

Is pretty simple but apparently still has some problem(s).

 

I originally tried passing the override variable in the session, from the mobile site, but that didn’t work and I’m assuming because our mobile site is on a different domain which keeps track of its own list of active sessions, different from the active session list kept by our main site’s( www.stchas.edu ) domain. I say this because I could never  get the right value of the override variable to show up in our main site’s domain when coming from the mobile site, when trying to pass it in the session. So then I started passing the value as a parameter in the query string to get it from the mobile site to our main site, and that did seem to work.

 

Can someone confirm this one way  or the other as to whether sessions are tracked differently between different domain hosts?

 

Can anyone see any problems with the logic as is?

 

This is the first time I’ve done anything like this and so I’m at least less knowledgeable, if not a beginner, in trying to do it. I’ll try to watch for responses tonight, but may not be able to respond until tomorrow.

 

Thanks for the help.

 

Henry

 

 

 

 

Falzone, Chris

unread,
May 23, 2013, 8:14:07 AM5/23/13
to dot...@googlegroups.com

> Can someone confirm this one way  or the other as to whether sessions are tracked differently between different domain hosts?

Yes, the session is tracked by the cookie JSESSIONID, which is saved to the host you are on.  This is why if you log into dotCMS on your www host and then go to your m host it are not logged in anymore.

You can get around this by using the response object to set a cookie instead of using the session.  The important thing to remember is to set the cookie and then get the cookie from the same domain:

You can see an example of this here:  http://dotcms.com/codeshare/set-cookies-via-header-requests?


> Can anyone see any problems with the logic as is?

I don't see any problem, though I might be missing it.  However, there are known issues when using the response object's sendRedirect method in templates.  Check your log when you hit the redirect and make sure you are not getting a message like Invalid State Exception or something to that effect.  The thing is, you cannot use the sendRedirect method if the response has already been sent to the browser because it needs to add a header value.  Try it in a blank template and see if that works.


Hope it helps



--
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
Visit this group at http://groups.google.com/group/dotcms?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Christopher Falzone

Interactive Developer


A Q U E N T

Digital, Creative, and Marketing Talent


aquent.com

cfal...@aquent.com

Henry Versemann

unread,
May 23, 2013, 9:12:35 AM5/23/13
to dot...@googlegroups.com

Chris,

 

So what log or logs should I be looking at to see if there’s a problem with the sendRedirect?

 

Thanks.

 

Henry

Falzone, Chris

unread,
May 23, 2013, 9:35:23 AM5/23/13
to dot...@googlegroups.com
dotcms.log and dotcms-velocity.log 

Henry Versemann

unread,
May 23, 2013, 9:36:14 AM5/23/13
to dot...@googlegroups.com

Thanks. I’ll take a look to see if it’s happening.

Henry Versemann

unread,
May 23, 2013, 12:26:05 PM5/23/13
to dot...@googlegroups.com

Chris,

 

If I have javascript code in in the same branch of Velocity code logic as the sendRedirect would that prevent either the sendRedirect or the javascript from working?

 

What if the container containing the vtl file code reference were placed in the template above the “<!DOCTYPE html” tag reference?

 

I’m looking for anything that could cause a conflict, in the sendRedirect branch of logic, because it’s the only one not working at this point.

 

The branching logic at the end of the vtl file referenced in the container itself looks like this:

 

#if($thisIsAMobileDevice)  

    #if($UtilMethods.isSet($rdrctOverride) && ($rdrctOverride))

        <script type="text/javascript">

            alert("Override flag set to " + "$rdrctOverride" + " and you will not be redirected to the new mobile website but instead sent to 'index.html' !...");

        </script>

    #else

        <script type="text/javascript">

            alert("You would now normally be redirected to the new mobile website at this point!...");

        </script>

        $response.sendRedirect('http://m.stchas.edu') 

    #end

#else

#end

 

Let me know when you can. Thanks again for the help.

Falzone, Chris

unread,
May 23, 2013, 12:49:01 PM5/23/13
to dot...@googlegroups.com
You cannot print anything out before $response.sendRedirect  .. including javascript.

Henry Versemann

unread,
May 23, 2013, 1:01:25 PM5/23/13
to dot...@googlegroups.com

OK thanks.

Reply all
Reply to author
Forward
0 new messages