logo

$25
WordPress Permalinks + PHP Sessions = Sad Panda

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?

spivurno | 09/07/10 at 3:37pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    09/08/10
    4:16pm
    Tobias Nyholm says:

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

  • avatar
    Last edited:
    09/07/10
    7:23pm
    Utkarsh Kukreti says:

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

  • avatar
    Last edited:
    09/08/10
    4:16pm
    Denzel Chia says:

    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.

    Previous versions of this answer: 09/08/10 at 10:58am

    • 09/09/10 8:49am

      spivurno says:

      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!

This question has expired.





Current status of this question: Completed