Forum Moderators: coopster

Message Too Old, No Replies

IE Cookie/Redirect/Refresh problems

         

aobrien5

4:59 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



Google has always solved my issues in the past, but after hours of frustrated searching and testing, here I am.

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.

jatar_k

7:29 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld aobrien5,

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.

aobrien5

8:07 pm on Feb 9, 2005 (gmt 0)

10+ Year Member



Hi and thanks for the reply. Yes save() is a user defined function, and it is listed below. Thanks again for any help.

$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

aobrien5

5:32 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



<bump> Any ideas?

Zipper

5:45 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



where and how do you define $redirectPath? also, have u tried META refresh?

<META HTTP-EQUIV=Refresh CONTENT="0; URL=http://www.domain.com/redirectpage.php">

aobrien5

6:01 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



I define it as such:

$redirectPath="http://ourserver.com/ftpclient/ftpclient.php";

I have tried a META refresh in the past, but not since my Location one was working. I will try it again now though.

Thanks for the reply.

aobrien5

6:07 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



Well, that's interesting. It does work. The other redirect was cleaner because this one does load the page before redirecting, but the cookies are saved properly. Interestingly enough, when the page loads, you can see that the checkboxes are not being loaded from the new cookie, but the previous one. But the redirected page does use the new cookie, obviously.

So this is a nice fix, but I would prefer the Location redirect if anyone has any ideas on that.

Thanks again Zipper.