• I faced that a page template code run automatically where I didn’t execute that page template.
    I have a example here.

    I have 1 page template named my_template.php

    <?php
    /*
    Template Name: my_template
    */
    $_SESSION['test_value'] = "wp Eror";
    ?>

    I have created 2 pages let page1 & page2 with my_template

    The code of my header.php is

    <?php
    //header.php
    echo "<pre>";
    print_r($_SESSION);
    echo "</pre>";
    
    //some code.

    Now I am browsing my wp site without those page1 & page2.
    Since I didn’t browse the page1 & page2 so the page template my_template.php shouldn’t be loaded. So I shouldn’t get the session value $_SESSION['test_value'] = "wp Eror"; in my site.

    Now the weird things is after browsing some pages ( without page1 & page2 ) of that site the session value will be loaded from the page template my_template.php. why ?
    since I didn’t view that page template why that page template was executed?

    any solution?
    Thanks in advanced.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Niaj Morshed

    (@niaj)

    One update
    The Session problem occurred in Firefox but in Google Chrome it seems ok.

    Moderator bcworkz

    (@bcworkz)

    What browser you’re using shouldn’t have any effect except one may display the output differently than the other. The header isn’t the best place to output content. Try checking your source view, the same content should be there in both browsers.

    I’m not able to replicate the behavior, I would have to speculate it’s due to something quirky your theme is doing, like loading templates even if they are not used. Try copying your template to twentyfourteen, then activating that theme. You shouldn’t be seeing any such $_SESSION value except on the pages in question.

    Thread Starter Niaj Morshed

    (@niaj)

    Thanks @bcworkz
    I also think, that was the theme problem. But is it possible to predict for which code this is happenning?

    Moderator bcworkz

    (@bcworkz)

    Not precisely. Look for code that executes when the theme loads,as opposed to code in functions, unless that function is called when the theme loads. Look at all include and require statements, including the “once” variants. Also look for functions that could contain such statements, like load_template().

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘weird $_SESSION problem in wp page template’ is closed to new replies.