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 fresh 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'];
?>