Jump to content

[SOLVED] Deleting old and creating a new cookie each time a page is refreshed.


John_S

Recommended Posts

Hello everybody,

 

I have a small problem with cookies, I would like to generate a value into a cookie each time a page is refreshed. Right now I use

 

if (isset($_COOKIE['verification'])) {

        $v_w = $_COOKIE['verification'];

        setcookie('verification', "", time()-3600);

    }

    else {

        $salt = rand(1, 100);

        $v_w = crypt($salt, $salt);

        setcookie('verification', $v_w, time()+1);

    }

 

But it gives me an empty cookie (= no cookie at all) each 1/2 page refresh. Does anybody know how could I fix this?

 

Thanks a lot in advance!

John

setcookie('verification', $v_w, time()+1);

 

You are setting the cookie for 1 second from now....try doing it for a bit more than that.

 

Yes I know but if I set it for a longer time each time that the page is refreshed the cookie will stay the same and that's what I am trying to avoid.

Let me ask you this, is there a reason you are not using sessions for this?

 

Hello,

Yes because I use an integrated software that doesn't support sessions :S Anyway, I have solved the issue, all I had to do is to move my code from one file to another and change it just a bit.

 

Thanks for the help anyway! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.