Browser Cookie Set/Get Issue

S

Sucpraran

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top