Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2013-01-04 16:04:43
- fyankai
- Member
- Registered: 2008-07-07
- Posts: 22
Strange cookie behaviour in Chrome
Hi All
I’ve got something really strange which may or may not be a textpattern thing:
I’ve got a site where each time you visit the home page you get a different image. A PHP cookie is incremented on each page load and it displays image 1, 2 or 3 accordingly. For some reason, it works fine in all browsers except Chrome.
So I tried to simplify as much as possible and ended up with this as my default page template:
<txp:php>
global $counter;
if (!isset($_COOKIE[“counter”])) {
$counter = 1;
setcookie(“counter”, $counter, time()+2592000, “/”);
echo “no previous cookie found<br />”;
} else {
echo “loading cookie…<br />”;
$counter = $_COOKIE[“counter”] + 1;
if ($counter > 3) {
$counter = 1;
}
setcookie(“counter”, $counter, time()+2592000, “/”);
}
echo $counter;
</txp:php>
When I load this in most browsers I get: “loading cookie…” followed by 1, 2 or 3 each time I refresh. When I load in Chrome, I just get “no previous cookie found/1”. I tried on my local copy of the site (running on MAMP) and get the same results.
So then I tried copying the above code into a fresh install of TXP. Interestingly it behaves differently: it works as it should in Chrome.
I’ve also tried deleting the cookies in Chrome, that doesn’t help.
I’m not really sure what could be causing this. I’ve now got two TXP sites, each with identical default pages, and they’re behaving very differently with this code.
Any ideas what might be causing this?
Thanks loads, Frank
Offline
Re: Strange cookie behaviour in Chrome
Do you have an URL that demonstrates the problem?
Offline
#3 2013-01-04 17:03:05
- fyankai
- Member
- Registered: 2008-07-07
- Posts: 22
Re: Strange cookie behaviour in Chrome
I don’t I’m afraid – I have to keep the live site in tact so I can’t really leave it’s home page up as a test…
But I did just realise something: the difference between the site that is experiencing this issue and the vanilla one I set up to test against is that the vanilla one has Production status “Debug”. If I switch it to “Live” it behaves just like my actual site, and breaks in Chrome.
So this is actually quite an easy thing to test: just copy the above code into the default page template of a TXP site, set Production status to “Live” and you should find it works in all browsers except Chrome…
As far as I can tell the only difference as far as the browser is concerned is that in Debug mode there’s some extra stuff output by TXP:
<!— Runtime: 0.0076 —>
<!— Query time: 0.003260 —>
<!— Queries: 7 —>
<!— Memory: 2623Kb, end of textpattern() —>
For some reason that seems to help Chrome work with the cookies – when it’s not there, it doesn’t work. Any ideas?
Thanks, Frank
Offline
Re: Strange cookie behaviour in Chrome
Try disabling the Send "Last-Modified" header?
preference. That’s only effective if the production status is live.
Offline
#5 2013-01-07 11:31:46
- fyankai
- Member
- Registered: 2008-07-07
- Posts: 22
Re: Strange cookie behaviour in Chrome
That’s the one – thanks for your help!
Offline