Forum Moderators: coopster
I have a site that's working perfectly when run on my own machine for testing, but when I copy it to the webserver, and access it from the outside address, I run into all kinds of refresh/cookie issues I've never seen before. Here's the situation:
The user is given a large list of checkboxes, the select the ones they want, and click Apply. This will call the same page, with an update=1 flag on the URL line, save all the selected boxes to a cookie, and redirect to another page.
However, if the header(location:...) line is not commented out, the cookie won't be saved and the page will be redirected. If it is commented out, the cookie will be saved, but the page will be displayed with the previous information (clicking refresh will refresh the page with the correct information) eventhough the page IS reading the cookie again before displaying everything.
Why will this save a cookie?:
save($mktlist, $chkAll);
// header("Location: ".$redirectPath);
But this won't?:
save($mktlist, $chkAll);
header("Location: ".$redirectPath);
I've tried every form of META/header tags to prevent caching of the pages, but nothing works. I've even set IIS to expire all the pages immediately, but I still have to hit refresh to see the new data. I've also set IE to request a new page every time, to no avail. And yes, this is kind of two problems in one. If I can get it to save the cookie and redirect like it does on my local IIS, I'd be happy.
Thanks very much for any help.
save($mktlist, $chkAll);
header("Location: ".$redirectPath);
what is the save function, I assume that is a user defined function. I can't specifically see anything from those lines you posted. Maybe if you post the code for that function we might be able to see a little more of what is going on.
$chkAll is a "Select All" check box on the form and $selectedMkts is an array of check boxes that lists the market names. There are 400+ markets, so if too many are selected, it has to be broken into multiple cookies.
function save($mktlist, $chkAll) {
$selectedMkts = $mktlist;
if ($chkAll == true ¦¦!$selectedMkts) {
if ($selectedMkts) $allChecked = true;
setcookie("StrataOptions1", "", time()+60*60*24*120);
if (isset($_COOKIE["StrataOptions2"])) {
setcookie("StrataOptions2", "", time()+60*60*24*120);
} //if
} else {
if (count($selectedMkts) >= 150) {
$selectedMkts1 = array_slice($selectedMkts, 0, 150);
$selectedMkts2 = array_slice($selectedMkts, 150, 150);
} else {
$selectedMkts1 = $selectedMkts;
} //if
if (!setcookie("StrataOptions1", serialize($selectedMkts1), time()+60*60*24*120)) {
?>
<script language="JavaScript">
<!--
alert('Cookies must be enabled to save market display options.');
//-->
</script>
<?php
} else {
if ($selectedMkts2) setcookie("StrataOptions2", serialize($selectedMkts2), time()+60*60*24*120);
} //if
} //if
} //save
So this is a nice fix, but I would prefer the Location redirect if anyone has any ideas on that.
Thanks again Zipper.