Link to home
Start Free TrialLog in
Avatar of sandhya01
sandhya01

asked on

Cookies storing values even after closing the browser.

Hi all,
I am creating one cookie in a javascript and one cookie in a php page. I am setting them both with a expire date to '0' i.e of one cookie that's set:  setcookie("isQR","57",0,'/');

But still i see that when I close the browser and open another page, I can see that the cookies are still there, theoreticallly it should have been deleted after the browser is closed.
But why I am not seeing it happening. Please let me know how to proceed. I want the cookies to get deleted as soon as the browser is closed.

Thanks.
Avatar of HonorGod
HonorGod
Flag of United States of America image

If you don't specify an expiration time, then a cookie should be a session cookie, and expire when the browser closes.

Please show us the code for your setcookie() routine.
just to add to what HonorGod said,, if you are using browsers with tabs then be careful while testing. closing tab is different from closing browser window.. session remains active even if you close the tab..
Avatar of sandhya01
sandhya01

ASKER

Hi Experts,
Please find the javascirpt code and php code for setting cookies in php and javascript page respectively.
After doing some testing i had the following observation:
1. If I open a single IE window and access the page in which cookies are set after I provide my login id and password, and then close it and if I try to open it again, I see that there are no cookies available, means closing the window destroys the cookies ---As per Expectation
2. If I open 2 different IE windows at the same time and then try to access the page in one of the IE windows and then close that particular IE window and If I try to open that page again in IE window I see that the cookies are still there - Not Per Expectation

So, somehow the second IE window is either delaying the deletion of cookies are not allowing them to net get deleted at all!, I am not able to understand this behaviour as the cookie is supposed to be set for a particular domain and the second IE window is not accessing any page in that domain( do I have to explicitly mention the domain also while setting cookie or by default the cookie takes the domain value in which it is created?).

Waiting for your expert suggestion

Thanks


//call to the function create cookies
createCookie('isQR','57',0,'/');
 
//actual function code
function createCookie(name, value, expires, path) {
	document.cookie = name + "=" + escape(value) + "; ";
	
	if(expires){
		expires = setExpiration(expires);
		document.cookie += "expires=" + expires + "; ";
	}
	if(path){
		document.cookie += "path=" + path + "; ";
	}
	
}
 
 
//php code to set cookie
setcookie("isQR","57",0,'/');

Open in new window

How are you opening the two IE windows?

Using File->New Window will just give you two windows with the same session

At least it used to with IE6/7
What code do you have for setCookie() and setExpiration()?
Hi
Please find the setExpiration() code:
fuction setExpiration(CookieLife)
{
var today = new Date();
var expr = new Date(today.getTime() + cookieLife *24*60*60*1000)
return expr.toGMTString();
}

yes, I am opening two windows one by one seperately not as tab, I am using IE 6.0 and I am clicking desktop IE icon for opening IE.

Thanks


ok, setExpiration() looks reasonable.

What about setCookie() ?
Cookies are stored at client browser, so they are not deleted , but you set expiration time.

For a comprehensive cookie tutorial, look at

http://javascriptjournal.com/ws/?p=54

Please feel free to view source
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try not to cache the page.

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 EST");
Hi All,
Thanks for the comments...let me try out your comments...will let you know
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I recommend #24909989, but I may be biased.  :)
>> I recommend #24909989 <<

I agree.  I believe my post at http:#a24943026 adds a bit but the answer is in the comment at http:#a24909989 .

bol