views:

74

answers:

4

Hi,

I'm experiencing a weird problem that occurs when I change the default permalinks in WordPress.

When I place this code in my functions.php file in my theme (or even in the root index.php file in WordPress) and navigate between and updating a few pages (for example the /about page), my counter often runs twice.

This problem is reproduced on every server I tried and on any theme or WordPress installation. Another thing that makes my brain even more confused is that it does not occur in Safari, Internet Explorer (6, 7 & 8), but only in Firefox. I'm using Firefox 3.6.8 and has tried it in both Mac OS X and Windows XP.

session_start();

$counter = $_SESSION['wp_action_counter'];

if( !isset($counter) ){
$counter = 0;
}

$counter++;

echo $counter;

$_SESSION['wp_action_counter'] = $counter;

My .htaccess rules looks like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I'm curious why this happens and is ever thankful to the one who can help me solve the problem.

A: 

If it is incrementing twice, this two requests are going to your server, check the server log, or install firebug and watch the net tab, this way you can get sure what's really going on, instead off assuming what it could be (a link is prefetched, a php-generated image is being requested..).

aularon
A: 

Just an idea... is there a broken image, script, css (or something like) path that starts a second request? I had that problem a time ago and IE cached the resulting 404 but FF always re-requestet the broken image. The image-path was rewritten to my index path that triggered a counter...

hacksteak25
A: 

I have finally found out what is the problem.

When I have <?php wp_head(); ?> in my header, WordPress adds this line:

<link rel='next' title='About' href='http://mysite.dev/about/' />

This link is prefetched and this is the cause why the counter runs twice. Adjusting the output of wp_head(); or removing it solves the problem.

Fred Bergman
A: 

You can find information on how to control the output in your header here: http://wpquicktips.wordpress.com/2010/08/30/keep-a-track-of-what-happens-in-your-header-and-footer/

Vincent