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

WordPress Permalinks + PHP Sessions = Sad Panda WordPress

  • SOLVED

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

http://stackoverflow.com/questions/3661247/problem-with-php-sessions-in-wordpress-with-non-default-permalinks

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

Answers (3)

2010-09-07

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'"));
$visits++;
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'");
}

2010-09-08

Denzel Chia answers:

Hi,

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.

Thanks.


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!

2010-09-07

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);