Loading ...
Sorry, an error occurred while loading the content.

Browser Set/Get Cookie Issue

Expand Messages
  • sucpraran
    Hi: We are using Cookies in our application to track user session. It works 95% but fails in occations. We could not find any pattern for this. Below is the
    Message 1 of 5 , Sep 29, 2003
    • 0 Attachment
      Hi:

      We are using Cookies in our application to track user session. It
      works 95% but fails in occations. We could not find any pattern for
      this. Below is the code to Set and Get cookies. In the occations
      when it fails, we get nothing in getCookie as if cookie is not set.
      We verified Browswer Setting and all of them accept cookies. We try
      to find a pattern with Broswer types/versions and OS types/versions
      but could not come with a pattern.

      This happens on those particular PC. The same user might be able to
      login by logging in from different PC. So far no clue on what could
      be the error. Any suggestion on where to look at.

      Thanks



      ---------------------------------------------------------------------
      --------------------------
      <Begin: Perl Code to Set/Get Cookie Cookie Name: CSSession>
      sub setCookie
      {
      my $name = $_[0] ;
      my $value = $_[1] ;
      my $Time = $_[2] ;
      my %MonthNames = (1=>"Jan", 2=>"Feb", 3=>"Mar", 4=>"Apr",
      5=>"May", 6=>"Jun", 7=>"Jul", 8=>"Aug", 9=>"Sep", 10=>"Oct",
      11=>"Nov", 12=>"Dec") ;
      my %Wdays = (0=>"Sunday", 1=>"Monday", 2=>"Tuesday",
      3=>"Wednesday", 4=>"Thursday", 5=>"Friday", 6=>"Saturday") ;
      my $secure = " secure" ;
      my $seconds = time() + ($Time*60) ;
      my @GMtime = gmtime($seconds) ;
      my $Cyear = $GMtime[5] + 1900 ;
      my $Cmonth = $GMtime[4] + 1 ;
      my $expiration = sprintf("$Wdays{$GMtime[6]}, %02d-$MonthNames
      {$Cmonth}-%02d %02d:%02d:%02d GMT", $GMtime[3], $Cyear, $GMtime[2],
      $GMtime[1], $GMtime[0]) ;
      my $path = "" ;
      my $domain = "" ;
      my $cookiestr = "Set-Cookie: $name=$value; expires=$expiration" ;
      return "$cookiestr" ;
      }


      sub getCookie
      {
      my ($GlobalPtr) = @_ ;
      my (@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
      $GlobalPtr->{'INCOOKIE'} = $ENV{'HTTP_COOKIE'} ;
      foreach(@rawCookies)
      {
      ($key, $val) = split (/=/,$_);
      $GlobalPtr->{$key} = $val;
      }
      }
      <End: Perl Code to Set/Get Cookie>

      <JavaScript function to verify the cookie properties of browser>
      <script language="JavaScript1.3">
      <!--
      function GetSessionID (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen)
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
      return getSessionVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
      }
      return null;
      }
      function getSessionVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
      endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
      }
      function focusAt(formname, felement){
      window.document.forms[formname].elements[felement].focus();
      }
      function CheckSettings() {
      var agt = navigator.userAgent.toLowerCase();
      var appname = navigator.appName.toLowerCase() ;
      var is_major = parseInt(navigator.appVersion);
      var is_minor = parseFloat(navigator.appVersion);
      var SessionID = GetSessionID('CSSession') ;
      var clen = 0 ;
      __redirectflag__
      if(SessionID != null) {
      clen = SessionID.length ;
      document.LOGINFORM.userID.focus();
      }
      else {
      if(RedirectFlag == 0) {
      document.location.href="__nocookieurl__" ;
      }
      }
      }
      //-->
      </script>
      ---------------------------------------------------------------------
      --------------------------
    • Damien Carbery
      ... Why are you not using CGI.pm? Among loads of other things it will parse the HTTP_COOKIE data out for you. It has been tried and tested and can be assumed
      Message 2 of 5 , Sep 29, 2003
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "sucpraran" <sucpraran@y...> wrote:
        > Hi:
        >
        > We are using Cookies in our application to track user session. It
        > works 95% but fails in occations. We could not find any pattern for
        > this. Below is the code to Set and Get cookies. In the occations
        > when it fails, we get nothing in getCookie as if cookie is not set.
        > We verified Browswer Setting and all of them accept cookies. We try
        > to find a pattern with Broswer types/versions and OS types/versions
        > but could not come with a pattern.
        >
        > This happens on those particular PC. The same user might be able to
        > login by logging in from different PC. So far no clue on what could
        > be the error. Any suggestion on where to look at.
        >
        > Thanks
        >
        >
        >
        > ---------------------------------------------------------------------
        > --------------------------
        > <Begin: Perl Code to Set/Get Cookie Cookie Name: CSSession>
        > sub setCookie
        > {
        > my $name = $_[0] ;
        > my $value = $_[1] ;
        > my $Time = $_[2] ;
        > my %MonthNames = (1=>"Jan", 2=>"Feb", 3=>"Mar", 4=>"Apr",
        > 5=>"May", 6=>"Jun", 7=>"Jul", 8=>"Aug", 9=>"Sep", 10=>"Oct",
        > 11=>"Nov", 12=>"Dec") ;
        > my %Wdays = (0=>"Sunday", 1=>"Monday", 2=>"Tuesday",
        > 3=>"Wednesday", 4=>"Thursday", 5=>"Friday", 6=>"Saturday") ;
        > my $secure = " secure" ;
        > my $seconds = time() + ($Time*60) ;
        > my @GMtime = gmtime($seconds) ;
        > my $Cyear = $GMtime[5] + 1900 ;
        > my $Cmonth = $GMtime[4] + 1 ;
        > my $expiration = sprintf("$Wdays{$GMtime[6]}, %02d-$MonthNames
        > {$Cmonth}-%02d %02d:%02d:%02d GMT", $GMtime[3], $Cyear, $GMtime[2],
        > $GMtime[1], $GMtime[0]) ;
        > my $path = "" ;
        > my $domain = "" ;
        > my $cookiestr = "Set-Cookie: $name=$value; expires=$expiration" ;
        > return "$cookiestr" ;
        > }
        >
        >
        > sub getCookie
        > {
        > my ($GlobalPtr) = @_ ;
        > my (@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
        > $GlobalPtr->{'INCOOKIE'} = $ENV{'HTTP_COOKIE'} ;
        > foreach(@rawCookies)
        > {
        > ($key, $val) = split (/=/,$_);
        > $GlobalPtr->{$key} = $val;
        > }
        > }
        > <End: Perl Code to Set/Get Cookie>
        >
        > <JavaScript function to verify the cookie properties of browser>
        > snip
        > </script>
        >
        Why are you not using CGI.pm? Among loads of other things it will
        parse the HTTP_COOKIE data out for you. It has been tried and tested
        and can be assumed to be very stable.
        It also handles the getting and setting of cookies.
      • B.S.Sridhar
        ... Hello, Here is one of the possible trouble maker in IE: Check whether the *System Date* on the PC that fails is ahead of the Cookie Expiration Date! ...
        Message 3 of 5 , Sep 29, 2003
        • 0 Attachment
          --- Damien Carbery <daymobrew@...> wrote:
          > --- In perl-beginner@yahoogroups.com, "sucpraran"
          > <sucpraran@y...> wrote:
          > > Hi:
          > >
          > > We are using Cookies in our application to track
          > user session. It
          > > works 95% but fails in occations. We could not
          > find any pattern for
          > > this. Below is the code to Set and Get cookies. In
          > the occations
          > > when it fails, we get nothing in getCookie as if
          > cookie is not set.
          > > We verified Browswer Setting and all of them
          > accept cookies. We try
          > > to find a pattern with Broswer types/versions and
          > OS types/versions
          > > but could not come with a pattern.
          > >
          > > This happens on those particular PC. The same user
          > might be able to
          > > login by logging in from different PC. So far no
          > clue on what could
          > > be the error. Any suggestion on where to look at.
          > >
          > > Thanks
          > >
          > >
          > >
          > >
          >
          ---------------------------------------------------------------------
          > > --------------------------
          > > <Begin: Perl Code to Set/Get Cookie Cookie Name:
          > CSSession>
          > > sub setCookie
          > > {
          > > my $name = $_[0] ;
          > > my $value = $_[1] ;
          > > my $Time = $_[2] ;
          > > my %MonthNames = (1=>"Jan", 2=>"Feb", 3=>"Mar",
          > 4=>"Apr",
          > > 5=>"May", 6=>"Jun", 7=>"Jul", 8=>"Aug", 9=>"Sep",
          > 10=>"Oct",
          > > 11=>"Nov", 12=>"Dec") ;
          > > my %Wdays = (0=>"Sunday", 1=>"Monday",
          > 2=>"Tuesday",
          > > 3=>"Wednesday", 4=>"Thursday", 5=>"Friday",
          > 6=>"Saturday") ;
          > > my $secure = " secure" ;
          > > my $seconds = time() + ($Time*60) ;
          > > my @GMtime = gmtime($seconds) ;
          > > my $Cyear = $GMtime[5] + 1900 ;
          > > my $Cmonth = $GMtime[4] + 1 ;
          > > my $expiration = sprintf("$Wdays{$GMtime[6]},
          > %02d-$MonthNames
          > > {$Cmonth}-%02d %02d:%02d:%02d GMT", $GMtime[3],
          > $Cyear, $GMtime[2],
          > > $GMtime[1], $GMtime[0]) ;
          > > my $path = "" ;
          > > my $domain = "" ;
          > > my $cookiestr = "Set-Cookie: $name=$value;
          > expires=$expiration" ;
          > > return "$cookiestr" ;
          > > }
          > >
          > >
          > > sub getCookie
          > > {
          > > my ($GlobalPtr) = @_ ;
          > > my (@rawCookies) = split (/;
          > /,$ENV{'HTTP_COOKIE'});
          > > $GlobalPtr->{'INCOOKIE'} = $ENV{'HTTP_COOKIE'} ;
          > > foreach(@rawCookies)
          > > {
          > > ($key, $val) = split (/=/,$_);
          > > $GlobalPtr->{$key} = $val;
          > > }
          > > }
          > > <End: Perl Code to Set/Get Cookie>
          > >
          > > <JavaScript function to verify the cookie
          > properties of browser>
          > > snip
          > > </script>

          Hello,

          Here is one of the possible trouble maker in IE:

          Check whether the *System Date* on the PC that fails
          is ahead of the Cookie Expiration Date!

          :-)
          Sridhar.

          __________________________________
          Do you Yahoo!?
          The New Yahoo! Shopping - with improved product search
          http://shopping.yahoo.com
        • sucpraran
          Sridhar: What do you advice, As we can not control the system time on user desktop, what is the work around so that it will work. Thanks ... --
          Message 4 of 5 , Sep 30, 2003
          • 0 Attachment
            Sridhar:

            What do you advice, As we can not control the system time on user
            desktop, what is the work around so that it will work.

            Thanks

            --- In perl-beginner@yahoogroups.com, "B.S.Sridhar"
            <b_s_sridhar@y...> wrote:
            > --- Damien Carbery <daymobrew@y...> wrote:
            > > --- In perl-beginner@yahoogroups.com, "sucpraran"
            > > <sucpraran@y...> wrote:
            > > > Hi:
            > > >
            > > > We are using Cookies in our application to track
            > > user session. It
            > > > works 95% but fails in occations. We could not
            > > find any pattern for
            > > > this. Below is the code to Set and Get cookies. In
            > > the occations
            > > > when it fails, we get nothing in getCookie as if
            > > cookie is not set.
            > > > We verified Browswer Setting and all of them
            > > accept cookies. We try
            > > > to find a pattern with Broswer types/versions and
            > > OS types/versions
            > > > but could not come with a pattern.
            > > >
            > > > This happens on those particular PC. The same user
            > > might be able to
            > > > login by logging in from different PC. So far no
            > > clue on what could
            > > > be the error. Any suggestion on where to look at.
            > > >
            > > > Thanks
            > > >
            > > >
            > > >
            > > >
            > >
            > -------------------------------------------------------------------
            --
            > > > --------------------------
            > > > <Begin: Perl Code to Set/Get Cookie Cookie Name:
            > > CSSession>
            > > > sub setCookie
            > > > {
            > > > my $name = $_[0] ;
            > > > my $value = $_[1] ;
            > > > my $Time = $_[2] ;
            > > > my %MonthNames = (1=>"Jan", 2=>"Feb", 3=>"Mar",
            > > 4=>"Apr",
            > > > 5=>"May", 6=>"Jun", 7=>"Jul", 8=>"Aug", 9=>"Sep",
            > > 10=>"Oct",
            > > > 11=>"Nov", 12=>"Dec") ;
            > > > my %Wdays = (0=>"Sunday", 1=>"Monday",
            > > 2=>"Tuesday",
            > > > 3=>"Wednesday", 4=>"Thursday", 5=>"Friday",
            > > 6=>"Saturday") ;
            > > > my $secure = " secure" ;
            > > > my $seconds = time() + ($Time*60) ;
            > > > my @GMtime = gmtime($seconds) ;
            > > > my $Cyear = $GMtime[5] + 1900 ;
            > > > my $Cmonth = $GMtime[4] + 1 ;
            > > > my $expiration = sprintf("$Wdays{$GMtime[6]},
            > > %02d-$MonthNames
            > > > {$Cmonth}-%02d %02d:%02d:%02d GMT", $GMtime[3],
            > > $Cyear, $GMtime[2],
            > > > $GMtime[1], $GMtime[0]) ;
            > > > my $path = "" ;
            > > > my $domain = "" ;
            > > > my $cookiestr = "Set-Cookie: $name=$value;
            > > expires=$expiration" ;
            > > > return "$cookiestr" ;
            > > > }
            > > >
            > > >
            > > > sub getCookie
            > > > {
            > > > my ($GlobalPtr) = @_ ;
            > > > my (@rawCookies) = split (/;
            > > /,$ENV{'HTTP_COOKIE'});
            > > > $GlobalPtr->{'INCOOKIE'} = $ENV{'HTTP_COOKIE'} ;
            > > > foreach(@rawCookies)
            > > > {
            > > > ($key, $val) = split (/=/,$_);
            > > > $GlobalPtr->{$key} = $val;
            > > > }
            > > > }
            > > > <End: Perl Code to Set/Get Cookie>
            > > >
            > > > <JavaScript function to verify the cookie
            > > properties of browser>
            > > > snip
            > > > </script>
            >
            > Hello,
            >
            > Here is one of the possible trouble maker in IE:
            >
            > Check whether the *System Date* on the PC that fails
            > is ahead of the Cookie Expiration Date!
            >
            > :-)
            > Sridhar.
            >
            > __________________________________
            > Do you Yahoo!?
            > The New Yahoo! Shopping - with improved product search
            > http://shopping.yahoo.com
          • B.S.Sridhar
            ... Hello, Set the expiration date *relative* to the current time like +1d (for the next one day) or +1M (for the next one month) which is available with
            Message 5 of 5 , Sep 30, 2003
            • 0 Attachment
              --- sucpraran <sucpraran@...> wrote:
              > Sridhar:
              >
              > What do you advice, As we can not control the system
              > time on user
              > desktop, what is the work around so that it will
              > work.
              >
              > Thanks
              >

              Hello,

              Set the expiration date *relative* to the current time
              like +1d (for the next one day) or +1M (for the next
              one month) which is available with CGI.pm. Or if u
              want to give the specific expiry time, get the
              client-side time, add the duration for which u want
              the cookie to live, and set the same.

              Sridhar.

              __________________________________
              Do you Yahoo!?
              The New Yahoo! Shopping - with improved product search
              http://shopping.yahoo.com
            Your message has been successfully submitted and would be delivered to recipients shortly.