Luey
asked on
Destroy Cookie??
Can someone please tell me why this will not destroy cookies in internet explorer 7. It seems to work fine in all other browsers.
<?php
/*---------------------------------------------------------------------------------*/
if (isset($_COOKIE['countyANSI'])) {
$date_of_expiry = time()- 60; //destroys cookies by setting expiration date 60 seconds in the past
setcookie( "countyANSI", "none", $date_of_expiry, "/" ) ;
setcookie( "stateANSI", "none", $date_of_expiry, "/" ) ;
}
/*---------------------------------------------------------------------------------*/
$go_to = "index.php";
header("Location: " . $go_to );
?>
Set your domain instead of /
ASKER
Hey Gary
Tried that just now and it still does not work in ie7. Works every where else.
I have another program written just like this one for another cookie and it works fine.
I can't even change the value of these two cookies I have tried. That is also a problem for me. Any suggestions.
Tried that just now and it still does not work in ie7. Works every where else.
I have another program written just like this one for another cookie and it works fine.
I can't even change the value of these two cookies I have tried. That is also a problem for me. Any suggestions.
<?php
/*---------------------------------------------------------------------------------*/
if (isset($_COOKIE['countyANSI'])) {
$date_of_expiry = time()- 60; //destroys cookies by setting expiration date 60 seconds in the past
setcookie( "countyANSI", "none", $date_of_expiry, "http://www.webcahoot.com" ) ;
setcookie( "stateANSI", "none", $date_of_expiry, "http://www.webcahoot.com" ) ;
}
/*---------------------------------------------------------------------------------*/
$go_to = "index.php";
header("Location: " . $go_to );
?>
What format are you using to set them? Make sure it is exactly the same.
ASKER
This is the way they were originally set. All this has worked several days ago or at least I was pretty sure it did. Now I cannot even change the cookie with this code.
setcookie( "countyANSI", "", time()-3600, "http://www.webcahoot.com") ;
setcookie( "stateANSI", "", time()-3600, "http://www.webcahoot.com") ;
/*---------------------------------------------------------------------------------*/
//sets cookie for county and state on change location
if (isset($_GET['county'])) {
$reload_page = $_GET['return_page'];
//if they click on a location set the cookie for the location and reload the parent page
$county = $_GET['county'];
$state = $_GET['state'];
$number_of_days = 999 ; //variable for days to set cookie to expire
$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days ; //does math to put the number of days into seconds
setcookie( "countyANSI", "$county", $date_of_expiry, "http://www.webcahoot.com") ;
setcookie( "stateANSI", "$state", $date_of_expiry, "http://www.webcahoot.com") ;
header("Location: " . $reload_page );
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
got it to work then thanks.
You're welcome.
ASKER
Help Again!
This works in ie7 but does not work in firefox
This works in ie7 but does not work in firefox
setcookie( "countyANSI", "", time()-3600, "/", "webcahoot.com") ;
How are you testing it?
ASKER
The site is actually live. The problem is I know it was working before but now it does not. I don't know any other way to explain it. The destroy I was trying to do was just trying to see if I removed the cookie could I make it work again. The site is WebCahoot.com and at the top of the page you can set a location. Like I said it all works except IE7. Any help would be greatly appreciated.
But you're not telling me how you are checking it so I can test it too!!
In Firefox 14, I'm getting the PHPSESSIONID cookie and the Google cookies but nothing else.
ASKER
Ok I put all the code back to the way it was. I know it is wrong. When you visit the site at the top of the page you will see "Click Here To Change Location". That make an ajax call. Then put in a zip code or city. It will search for your location. When you click the link for your location it calls a program that sets the cookie and reloads the page. This should change the field to say your location. I am also echoing one of the cookies in the footer. The way it is now works everywhere except ie7. I have tried the code the way you suggested but then cant get it to work in firefox but does work in ie. What next. Thanks so much for you time.
The code that I showed you above works perfectly on my own site in Firefox14 and IE7. The only change I made in the format was to add a '.' in front of the domain name because the Google cookies are doing that. Try putting this at the top of your 'index.php' page and I think you'll see that it works. It may be the AJAX process that is screwing it up somehow. I don't see anything in the footer of your page.
setcookie( "countyANSI", "County", time()+3600, "/", ".webcahoot.com") ;
setcookie( "stateANSI", "State", time()+3600, "/", ".webcahoot.com") ;
ASKER
One question am I having a problem because I already have cookies set with the same name but wrong format. Just guessing. Because everytime I put anything to the right of "/" it stops working in firefox but will work in ie7. If so do I need to correct the code and change all the instances of that cookie name in my other programs. The site has not been up long so there would not be to many people with the wrong cookies. If that is the problem because I have followed your instruction to the t and it still does not work. I even found that the php manual say you may need a . for older browsers in front of the domain to match all subdomains.
You can change the cookie name because right now it isn't working. Show me what you mean by anything to the right of "/".
Here are two simple pages that set and delete the cookies. They link to each other so you can just go back and forth and see that it works. 'cookie11.php' sets the cookies and displays the cookies sent with the request. 'cookie22.php' deletes the cookies and displays the cookies sent with the request. The differences between them are very small.
cookie11.php
cookie22.php
cookie11.php
<?php
// cookies test
//setcookie( "countyANSI", "Sacramento", time()+3600, "/", ".webcahoot.com") ;
//setcookie( "stateANSI", "California", time()+3600, "/", ".webcahoot.com") ;
// use default domain
setcookie( "countyANSI", "Sacramento", time()+3600, "/") ;
setcookie( "stateANSI", "California", time()+3600, "/") ;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>cOOKIE tEST Pages</title>
</head>
<body>
<div id="wrap">
<h1>cOOKIE tEST Pages</h1>
<div style="font-size: 10pt; font-family: Arial; font-weight: bold; text-align: center; color: #330066;">
<script type="text/javascript">
<!--
/*Current date script credit:
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Surfin' Sunday","Moody Monday","Totally Tuesday","Wild Wednesday","Thrilling Thursday","Finally Friday","Shopping Saturday")
var montharray=new Array("Jan","Feb","Mar","April","May","June","July","Aug","Sept","Oct","Nov","Dec")
document.write(dayarray[day]+" "+montharray[month]+" "+daym+", "+year)
// -->
</script>
</div>
<!-- ****** Comments and Current Events ****** -->
<div align="center">
<?php var_dump($_COOKIE); ?>
<br />
<a href="cookie22.php">cookie22.php</a>
</div>
<hr class="hr2">
</body>
</html>
cookie22.php
<?php
// cookies test
//setcookie( "countyANSI", "Sacramento", time()-3600, "/", ".webcahoot.com") ;
//setcookie( "stateANSI", "California", time()-3600, "/", ".webcahoot.com") ;
// use default domain
setcookie( "countyANSI", "Sacramento", time()-3600, "/") ;
setcookie( "stateANSI", "California", time()-3600, "/") ;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>cOOKIE tEST Pages</title>
</head>
<body>
<div id="wrap">
<h1>cOOKIE tEST Pages</h1>
<div style="font-size: 10pt; font-family: Arial; font-weight: bold; text-align: center; color: #330066;">
<script type="text/javascript">
<!--
/*Current date script credit:
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Surfin' Sunday","Moody Monday","Totally Tuesday","Wild Wednesday","Thrilling Thursday","Finally Friday","Shopping Saturday")
var montharray=new Array("Jan","Feb","Mar","April","May","June","July","Aug","Sept","Oct","Nov","Dec")
document.write(dayarray[day]+" "+montharray[month]+" "+daym+", "+year)
// -->
</script>
</div>
<!-- ****** Comments and Current Events ****** -->
<div align="center">
<?php var_dump($_COOKIE); ?>
<br />
<a href="cookie11.php">cookie11.php</a>
</div>
<hr class="hr2">
</body>
</html>
ASKER
"/", ".webcahoot.com"
That alone will not cause Firefox to fail. Something else is going on. The Google cookies for your site that use ".webcahoot.com" are working fine in Firefox.
Firefox says you have this error:
Timestamp: 8/10/2012 4:00:30 PM
Error: TypeError: $("#article_images").validate is not a function
Source File: http://www.webcahoot.com/javascript/webcahoot_javascript.js
Line: 126
ASKER
Ok I test your programs and see that they work fine. I also have some other cookies such as login etc that work fine. I will look at that error now.
Take the two programs and uncomment the first two cookie lines that use ".webcahoot.com" and comment out the next two lines that use the default domain and see what happens. Make the changes on both programs.
ASKER
I can make yours work both ways in ie but it does not work in ff like this.
setcookie( "stateANSI", "California", time()-3600, "/", ".webcahoot.com") ;
Like i said earlier if i use .webcahoot.com my code even works in ie but not ff.
setcookie( "stateANSI", "California", time()-3600, "/", ".webcahoot.com") ;
Like i said earlier if i use .webcahoot.com my code even works in ie but not ff.
I know what you said but I also know that it works perfectly that way on my website using my domain name. And it works the same in Firefox14, IE8, Chrome, Safari, and Opera on three different computers, IE7 on a third computer, Firefox 3.6 and Chrome on my Linux computer, and Firefox 2 on my old Mac. So I believe that if it is not working in your copy of Firefox14, then maybe there is something wrong with your copy. When you look at cookies for "webcahoot.com" in your copy of Firefox, do you see the Google cookies that use ".webcahoot.com"?
ASKER
Hold the presses. I think I have found the problem. All of your code works fine. However mine does not. I have another test to run but I think it is because I an not treating my variable properly. I changed your sacremento and california to some variables that are in the data. They are numbers like 045 and it failed to work. I know that is not an integer so how am supposed to be handling my variables.
From the ajax call I simply pass them in a url variable and get and asign them like below. What I am doing wrong with them. I hate I have wasted your whole afternoon.
$county = $_GET['county'];
$state = $_GET['state'];
From the ajax call I simply pass them in a url variable and get and asign them like below. What I am doing wrong with them. I hate I have wasted your whole afternoon.
$county = $_GET['county'];
$state = $_GET['state'];
Everything that goes into a cookie must be text except for the expire date. If you're trying to put an integer (binary value) into a cookie, that won't work because all cookie content is text. On the other hand, there is no obvious reason that your assignments below won't work.
$county = $_GET['county'];
$state = $_GET['state'];
ASKER
I know this sounds crazy but the only way I could make it work was to destroy the cookies in both formats before trying to change one.
Then I set them like this. It all seems to work now. I will have to test more.
setcookie( "countyANSI", "", time()-3600, "/", ".webcahoot.com") ;
setcookie( "stateANSI", "", time()-3600, "/", ".webcahoot.com") ;
setcookie( "countyANSI", "", time()-3600, "/") ;
setcookie( "stateANSI", "", time()-3600, "/") ;
Then I set them like this. It all seems to work now. I will have to test more.
setcookie( "countyANSI", "$county", $date_of_expiry, "/") ;
setcookie( "stateANSI", "$state", $date_of_expiry, "/") ;