Greetings all,
I have a small question with regards to setting cookies. I have found that if I try to set a cookie with a header preceding it the cookie will not set itself.
I have found that if I set a refresh rate of "0" while using a URL relocation the cookie sets itself fine.
Would anyone know why this does this?
Code example that does not work,
if (isset($_POST['submit'])) {
if ($_POST['fromdate'] != 'From Date') {
if (($_POST['todate']) != "To Date") {
setcookie('fromdate', $fromdate, time()+5, '/', '', 0);
setcookie('todate', $todate, time()+5, '/', '', 0);
header('location: search_results.php');
}
}
}
Code example that does work,
if (isset($_POST['submit'])) {
if ($_POST['fromdate'] != 'mm/dd/yyyy') {
if (($_POST['todate']) != "mm/dd/yyyy") {
setcookie('fromdate', $fromdate, time()+15, '/', '', 0);
setcookie('todate', $todate, time()+15, '/', '', 0);
header("Refresh: 0; URL=search_results.php");
}
}