php cookie and form submitting question

Joined
12 Feb 2006
Posts
17,633
Location
Surrey
can't see why i am having a problem here, probably will end up writing this thread and as soon as i submit i will see why but any way here goes.

ok so part of this site i am working on (just purely to teach myself php and was originally for coursework before it became so big) where the user can report a bad comment but choosing a radio button explaining why it has been reported and then submitting a form. a cookie is then set so that if they return it will say they have already posted a report for this particular comment, but then provide a link for them to post another.

now after the user submits the report everything happens as expected, securty checks etc, then if all good send and set cookie. the only problem is the checking of the cookie doesn't happen until a page refresh and i can't see why.

the basic order of the script:
  1. first thing it does is check if it should set cookie,
  2. then checks if cookie is set, if yes say form already sent,
  3. then checks if the form should be displayed.
when form is submitted cookie is set, form to report isn't displayed, however checking if the cookie is set doesn't happen until a page refresh

can anyone guess why from that quick explanation?
 
that's normal (afaik :p). i just use header to redirect the page after setting the cookie.

PHP:
setcookie(blah blah....)
header("Location: form.php");
exit;
 
Last edited:
that's normal. just use header to redirect the page after setting the cookie.

PHP:
setcookie(blah blah....)
header("Location: form.php");
exit;

i guess i could do that but why doesn't it check if the cookie is set? or is the problem that the cookie is set after the page is finished going through the script, if that makes sense? so php reads the whole page, then does what it needs to? or does it read it and do it as it goes? i would have thought second so again making me confused why the cookie isn't checked correctly

is there anyway to refresh the page with all the content in the url? i have a load of variables which are important and would like them to be sent without having to say, header("Location: form.php?commentId=".$commentId."&somethingElse=".$nextValue."); etc
 
Back
Top Bottom