Page 1 of 1

Cookie won't set...

Posted: Sun Jul 30, 2006 9:38 am
by Bitweiser
Hello Guy's,

I've got a strange thing going on.

I'm writing a cookie as follows:
setcookie("CookieName", $CookieValue, time()+3000);
Everything works fine and the cookie is written.
BUT... I only want the cookie to last 20 minutes so I've changed the time to 1200.
The instruction is now setcookie("CookieName", $CookieValue, time()+1200);
PROBLEM: The cookie isn't written anymore.

So my big question is: Why and can any of you wizzards out there help me?

To prevent any echo problems I'm using <?php ob_start(); ?> and <?php ob_end_flush(); ?> in the beginning and the end of the php-file.

TIA

Posted: Sun Jul 30, 2006 9:55 am
by feyd
I would imagine that the actual time sent to the browser is at or behind the time the browser thinks it currently is. If you have Firefox and the web developer extension, look at the response headers.

Posted: Sun Jul 30, 2006 9:56 am
by tecktalkcm0391
How do you know the cookie isn't written anymore?

Posted: Sun Jul 30, 2006 10:06 am
by RobertGonzalez
I would guess by checking to see if it is set...

Code: Select all

<?php
if (isset($_COOKIE['CookieName'])) {
    // cookie is set
}
?>

Posted: Sun Jul 30, 2006 10:20 am
by Bitweiser
tecktalkcm0391 wrote:How do you know the cookie isn't written anymore?
I use as said by Everah the Isset command. And when I look in the "cookie" folder at the clientside PC the cookie file isn't present.

You say "written anymore" but I say "Never written".

Posted: Sun Jul 30, 2006 10:24 am
by RobertGonzalez
Do like Feyd suggested... Set your cookie as in your original code and then check the server time and check the client time. If the two are not the same, then that could explain your issue.

Posted: Sun Jul 30, 2006 10:27 am
by Bitweiser
feyd wrote:I would imagine that the actual time sent to the browser is at or behind the time the browser thinks it currently is. If you have Firefox and the web developer extension, look at the response headers.
Sometimes the answer is just in front of your face but your to blind to see the solution. Indeed the timeindex on my server was wrong. I've reset the clock on the server and guess what....Now it works fine.

Thanks for your posts "feyd" and "Everah" you were both a great help 8)