Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WordPress Permalinks + PHP Sessions = Sad Panda WordPress


I did not post this question; however, it sums up my issues exactly:

Do permalinks cause pages to be run twice? Is there any way to prevent this behavior?

Answers (3)


Tobias Nyholm answers:

I had that problem when implanting a simple counter. The answer is: No, it does not.
That is a firefox 'thing'.

If you are trying to do something similar. Use queries instead of built in functions. That was my solution on the counter. Here is my the code in the single.php:

$visits=$wpdb->get_var($wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE post_id='$post->ID' AND meta_key='visit_count'"));
if($visits==1) {
$wpdb->query("INSERT INTO $wpdb->postmeta SET post_id='$post->ID', meta_key='visit_count', meta_value='$visits'");
} else {
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value='$visits' WHERE post_id='$post->ID' AND meta_key='visit_count'");


Denzel Chia answers:


After taking a look at link you posted. It seems like Firefox is following the links on the HTML header and causing reloading of webpage.

Add this in your functions.php before everything else.

remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
remove_action( 'wp_head', 'rel_canonical' );

This will remove unwanted links in your WordPress theme HTML head.
I think Firefox is following this links in the HTML head and reloaded the page.


spivurno comments:

For reference to anyone else who stumbles across this issue... this ended up being the preferred answer plus one addition.

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

Thanks Denzel!


Utkarsh Kukreti answers:

Can you add the following to your code, visit the site once in Firefox, and mail me the output? (from my profile)

file_put_contents('log.log', serialize($_SERVER), FILE_APPEND);