473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Browser Cookie Set/Get Issue

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>
Jul 19 '05 #1
0 3897

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Theo | last post by:
Question for the group The authentication system for the site Im working on seems to function properly and all is good. A session keeps track of everything and a cookie is used to accept or deny...
24
by: Nancy Drew | last post by:
hi all i'm trying to keep users from being able to login to a site twice at the same time. everytime a user does a login, i stick their userID into an application scoped array. if they try to...
11
by: David Lozzi | last post by:
Hello All, I am having an issue with thus far one computer on my client's web site. If the user loads the shopping cart and then closes all browser windows, then opens them back up, goes back to...
3
by: Ben | last post by:
Hi, I'm sending out a session cookie. That is a cookie that has no expiration date. When I surf through the site, no problems, but if I close the browser and open it back up, the cookie is still...
1
by: Tina | last post by:
When I use Request.Browser.Cookies I always get true returned. Even when the browser has cookie acceptance turned off. Why? Thanks, T
2
by: Niko | last post by:
Hi I have a big problem with some browser setting wrong ASP.NETSessionid in a cookie, and the result is that asp.net 1.1 always assigns new session to the client. I checked what is going on and...
0
by: etnaelk | last post by:
Hi all, I have a real bugger of a problem that I just haven't been able to figure out. I am working on writing my own proxy server in C# using TcpListener, TcpClient, HttpWebRequest/Response and...
5
by: bgold12 | last post by:
When a user logs onto my site, I set some session data using php: .... session_start(); .... $_SESSION = 'value'; .... From what I understand, this should store the session data (i.e. the...
12
by: jodleren | last post by:
Hi I did not notice. A system I have made, seems on one server to keep the $_SESSION even when the browser has been closed... How can I avoid that? WBR Sonnich
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.