473,608 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=$expira tion" ;
return "$cookiestr " ;
}
sub getCookie
{
my ($GlobalPtr) = @_ ;
my (@rawCookies) = split (/; /,$ENV{'HTTP_COO KIE'});
$GlobalPtr->{'INCOOKIE'} = $ENV{'HTTP_COOK IE'} ;
foreach(@rawCoo kies)
{
($key, $val) = split (/=/,$_);
$GlobalPtr->{$key} = $val;
}
}
<End: Perl Code to Set/Get Cookie>

<JavaScript function to verify the cookie properties of browser>
<script language="JavaS cript1.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.cooki e.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(docume nt.cookie.subst ring(offset, endstr));
}
function focusAt(formnam e, felement){
window.document .forms[formname].elements[felement].focus();
}
function CheckSettings() {
var agt = navigator.userA gent.toLowerCas e();
var appname = navigator.appNa me.toLowerCase( ) ;
var is_major = parseInt(naviga tor.appVersion) ;
var is_minor = parseFloat(navi gator.appVersio n);
var SessionID = GetSessionID('C SSession') ;
var clen = 0 ;
__redirectflag_ _
if(SessionID != null) {
clen = SessionID.lengt h ;
document.LOGINF ORM.userID.focu s();
}
else {
if(RedirectFlag == 0) {
document.locati on.href="__noco okieurl__" ;
}
}
}
//-->
</script>
Jul 19 '05 #1
0 3913

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

Similar topics

22
2866
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 access... sounds as it should be I hope. Then when all is done logging out destroys everything and the pages are no longer accessable. Good so far. But two things come to mind: one is preventing multiple logins of the user/password. The...
24
2447
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 login again, i bounce them to an error page. i use the session_onEnd sub within global.asa to remove their userID from the array at the end of their session, and this seems to work fine. however, if i just shut down the browser, the sub_onEnd...
11
5063
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 the site, the shopping cart information is there! The shopping cart info is only loaded into a session variable! There are no cookies on the site to store this information. Am I mistaken in believing when a browser window is closed that the session...
3
2239
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 there if other browser windows were open. Even if those windows didn't go to the site with the cookie or spawn from the browser that is visiting the site. This is causing a problem. People want to be able to close the browser to logout. How...
1
1111
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
1690
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 I noticed that the broswers set the sessionid inside quotation marks and I guess that ASP.NET 1.1 can't parse this and just assigns new session to the client. So my question is can I somehow intercept the request and fix this session id by my self...
0
1458
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 NetworkStream. I have everything working pretty well except images won't load to their location. ------------------------------------------------------------------------------------------------------------------...
5
4112
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 key-value pairs) in a cookie on the user's computer, and it should be
12
1980
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
8069
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8011
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8503
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8358
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6826
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3972
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4036
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1339
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.