is there a way to change the value of the setcookie() function in php based on a

Salmane S

New member
condition? what I am trying to do is this ( in Php)
setcookie with a certain default value.
if the user posts a form, the value of the cookie would be then changed
else the cookie will remain the same as before.
the code looks something like this:
setcookie('Cookie_name', $Cookie_Value, $Cookie_Expiration);
if ($_POST['form']) {
setcookie('Cookie_name', $Cookie_New_Value, $Cookie_Expiration);
}

the trouble i run into as you all can imagine is as follows:

Warning: Cannot modify header information - headers already sent by (output started at.....etc

I would greatly appreciate any advice on how to tackle this issue :)
thank you all very much :)
what I am trying to do is this ( in Php)
setcookie with a certain default value.
if the user posts a form, the value of the cookie would be then changed
else the cookie will remain the same as before.
the code looks something like this:
setcookie('Cookie_name', $Cookie_Value, $Cookie_Expiration);
if ($_POST['form']) {
setcookie('Cookie_name', $Cookie_New_Value, $Cookie_Expiration);
}
the trouble i run into as you all can imagine is as follows:
Warning: Cannot modify header information - headers already sent by (output started at.....etc

I would greatly appreciate any advice on how to tackle this issue :)
thank you all very much :)
I do appreciate the answer from Colath. I have to add that I am using Ajax for the form submission which puts another twist in this story. is there a way to avoid multiple files. something like cancel previous header or replace previous cookie settings with new ones? there ought to be a function like that on PHP I just cant put my finger on it. Thanks guys
 
Back
Top