Cookie difference IE/FF
am 07.10.2007 00:17:25 von Guillaume Dargaud
Hello all,
I'm trying to do something very simple: delete (or empty) a cookie.
The following code (which I found in the PHP doc) works fine in IE6 but not
in Firefox:
setcookie ("Cart", "", time() - 3600);
Any hint on what's wrong ? Yes, I issue this command before sending in any
HTML.
Thanks
--
Guillaume Dargaud
http://www.gdargaud.net/Antarctica/
Re: Cookie difference IE/FF
am 07.10.2007 07:40:46 von Macca
If you are trying to build a shopping cart i would highly reccommend
that you look into using sessions instead of a normal cookie.
see http://us3.php.net/manual/en/ref.session.php
Regards,
Paul
Re: Cookie difference IE/FF
am 07.10.2007 11:34:19 von Guillaume Dargaud
> If you are trying to build a shopping cart i would highly reccommend
> that you look into using sessions instead of a normal cookie.
Hmmm, yup. Given away by my variable name !
I want to do something extremely simple, so I thought it would be a good way
to do it. What's wrong with this approach ?
> see http://us3.php.net/manual/en/ref.session.php
OK, thanks, I'll look it up.
--
Guillaume Dargaud
http://www.gdargaud.net/
"If brute force doesn't solve your problems, then you aren't using
enough."
Re: Cookie difference IE/FF
am 07.10.2007 13:36:29 von colin.mckinnon
On 6 Oct, 23:17, "Guillaume Dargaud"
wrote:
> Hello all,
> I'm trying to do something very simple: delete (or empty) a cookie.
> The following code (which I found in the PHP doc) works fine in IE6 but not
> in Firefox:
> setcookie ("Cart", "", time() - 3600);
So you're asking the browser to create a cookie which should have
expired an hour ago. When one already exists. While this is documented
in the set_cookie() function page as way of achieving the desired
result, it strikes me as an ugly hack. I think a better way to solve
this would be to set a cookie which expires in the future with a value
indicating that it no longer references a valid server-side state.
If you can find something in the HTTP RFCs which says this should
work, then by all means raise it as a bug with the FireFox developers.
C.
Re: Cookie difference IE/FF
am 07.10.2007 14:02:41 von Macca
>Hmmm, yup. Given away by my variable name !
>I want to do something extremely simple, so I thought it would be a good way
>to do it. What's wrong with this approach ?
Not everyone has cookies enabled in their browser. Cookies are
problematic in this way and should only really be used for non-vital
data.
Sessions on the other hand are far more reliable.
Re: Cookie difference IE/FF
am 07.10.2007 18:46:49 von Vladimir Ghetau
On Oct 7, 1:02 pm, macca wrote:
> >Hmmm, yup. Given away by my variable name !
> >I want to do something extremely simple, so I thought it would be a good way
> >to do it. What's wrong with this approach ?
>
> Not everyone has cookies enabled in their browser. Cookies are
> problematic in this way and should only really be used for non-vital
> data.
>
> Sessions on the other hand are far more reliable.
Indeed, cookies are a problem on some browsers, however, using
alternative session/cookies it's better, just like google does, or
digg, or whatever.
If set_cookie fails, you can try using the header() PHP builtin
function, just by trying something like:
header('Set-Cookie: cookie_name=cookie_value; expires=Tue, 06-Oct-2009
16:36:23 GMT; path=/; domain=.yourdomain.com');
?>
This is slower than the regular PHP cookie version, however, at this
step, you get more feedback about what happens there.
See this example below, to learn how google does the cookie setting
part, and it seems to work just great:
http://www.xheaders.com/index.php?url=http%3A%2F%2Fwww.googl e.com%2F
(watch what happens inside the SET-COOKIE area)
In my opinion, cookies are good, however unsafe without any pre-
escaping/pre-processing activity.
On the other hand, sessions, are slower since disk access times are
slower than a cookie "PHP based" checkup based on your visitor's
browser feedback. This can be solved by storing sessions data inside
MYSQL, so everything is doable in one way or another.
So, when creating a web app, I prefer to use both cookies and
sessions, depending on what works for each user.
Try using JS to check existance of cookies, or anything else, there
are plenty of workarounds if you want to use them, however, try to
play safe and defensively when coding, you never know.
Best luck!
Vladimir Ghetau
http://www.Vladimirated.com
Re: Cookie difference IE/FF
am 08.10.2007 11:21:20 von Guillaume Dargaud
I found what the problem was: I had forgotten the path info '/' in one of
the setcookie calls and it was creating a great deal of confusion.
As to using sessions, I only need something very simple, and it doesn't need
to be secure (famous last words !) as security is handled by another system.
A javascript workaround handles the cookieless fine. As for the
scriptless... I even have a workaround for that.
But I'll keep it in mind. Thanks for the previous answers.
--
Guillaume Dargaud
http://www.gdargaud.net/Humor/LastWords.html
'Come out and say that, Tyson !'