开发者

PHP sessions: pageview count double incrementing in firefox3 and chrome4

I have some basic pageview incrementing code set up on a LAMP server (see code below).

The code starts a session, checks if pageviews is set, increments it if not and prints the variable. The page links to itself with a single href, and clicking on that link causes the pageviews count shown on screen to increment by one. It works correctly in IE8, Safari4 and Opera10. But in Firefox3 and Chrome4 it increments by two each time I click the link. I am using a f开发者_开发技巧resh install of both Chrome and Firefox, and I have tried this in Firefox safe mode as well.

Paradoxically, I have the exact same code working correctly on another live site on the same server.

This might be more of a browser question than a PHP question :-)

Thanks in advance for your help!

<?
// start session
session_start();

// increment page views
if (isset($_SESSION['pageviews'])) {
$_SESSION['pageviews'] ++;
}

// if new session, set page views at 1 and capture source URL
else {
$_SESSION['pageviews'] = 1;
$_SESSION['sourceurl'] = $_SERVER['HTTP_REFERER'];
}

// capture user ip address
$ipaddress = $_SERVER['REMOTE_ADDR'];
?>


Most usual cause is improper human-readable urls implementation, when router acts as a 404 handler, thus, nonexistent favicon.ico would make another request ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜