Jump to content

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


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! :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.