DHTML setCookie to bypass login page.

Discussion in 'Javascript' started by tungchau81@yahoo.com, Aug 24, 2006.

  1. Guest

    Hi everybody,
    In MainPage.jsp, I had simple code to redirect it to a page called
    'http://123.123.123.123' . However, I want to bypass the login page
    (http://123.123.123.123/login.htm) by setting cookie of authorization
    token, so that it will point directly to
    http://123.123.123.123/main.htm. Here is my code:

    ++++++++++++++++++++++++++++++++++++++++++++++++
    <html>
    <head>
    <title></title>
    var djConfig = {isDebug: true, debugAtAllCosts : true};
    </script>
    dojo.require("dojo.io");
    dojo.require("dojo.io.cookie");
    dojo.hostenv.writeIncludes();
    </script>
    function main() {
    if (dojo.io.cookie.isSupported() == true) {
    dojo.io.cookie.setCookie('xxx', 'yyy', null, null, null,
    null);
    var cookieValue = dojo.io.cookie.getCookie('xxx');
    alert(cookieValue);
    }
    document.location = 'http://123.123.123.123';
    }
    </script>
    </head>
    <body onload="main();"></body>
    </html>
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    alert(cookieValue) returns the correct value of the cookie. However, I
    still can not bypass the login page.

    I also tried the following approach, but then, alert(cookieValue)
    returns null.
    +++++++++++++++++++++++++++++++++++++++
    dojo.io.cookie.setCookie('xxx', 'yyy', 90, '/', '123.123.123.123',
    false);
    var cookieValue = dojo.io.cookie.getCookie('xxx');
    alert(cookieValue); /_/***returns null
    ++++++++++++++++++++++++++++++++++++++++

    My MainPage.jsp was the result of a webwork action which is similar to
    Struts action.

    Is there anything I m doing wrong here? I am really stuck and do not
    know what other approaches I should try. Any advice is greatly
    appreciated.

    P.S.: Here is the code of setCookie and getCookie in dojo library for
    your preference:
    dojo.io.cookie.setCookie = function(name, value, days, path, domain,
    secure) {
    var expires = -1;
    if(typeof days == "number" && days >= 0) {
    var d = new Date();
    d.setTime(d.getTime()+(days*24*60*60*1000));
    expires = d.toGMTString();
    }
    value = escape(value);
    document.cookie = name + "=" + value + ";"
    + (expires != -1 ? " expires=" + expires + ";" : "")
    + (path ? "path=" + path : "")
    + (domain ? "; domain=" + domain : "")
    + (secure ? "; secure" : "");
    }

    dojo.io.cookie.set = dojo.io.cookie.setCookie;

    dojo.io.cookie.getCookie = function(name) {
    // FIXME: Which cookie should we return?
    // If there are cookies set for different sub domains in the
    current
    // scope there could be more than one cookie with the same
    name.
    // I think taking the last one in the list takes the one from
    the
    // deepest subdomain, which is what we're doing here.
    var idx = document.cookie.lastIndexOf(name+'=');
    if(idx == -1) { return null; }
    var value = document.cookie.substring(idx+name.length+1);
    var end = value.indexOf(';');
    if(end == -1) { end = value.length; }
    value = value.substring(0, end);
    value = unescape(value);
    return value;
    }

    dojo.io.cookie.get = dojo.io.cookie.getCookie;

    Tung Chau
     
    , Aug 24, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,367
  2. Shannon

    login page stays on login page

    Shannon, Jan 9, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    561
    Shannon
    Jan 9, 2008
  3. Steve
    Replies:
    1
    Views:
    298
    Richard Cornford
    Apr 9, 2005
  4. bonus
    Replies:
    2
    Views:
    102
    Thomas 'PointedEars' Lahn
    Feb 24, 2008
  5. Priya

    hyperlink to Bypass login

    Priya, Apr 29, 2010, in forum: Javascript
    Replies:
    9
    Views:
    341
    Bwig Zomberi
    Apr 30, 2010
Loading...

Share This Page