PHP $_SESSION变量在页面模板上不更新


PHP $_SESSION variables not renewing on page template

页面A和页面B都使用PHP页面模板1,将get_the_title();存储在$_SESSION['pagesource'] = get_the_title();中并将其发送到另一个PHP文件

然而,在访问页面A之后,然后转到页面B,变量仍然显示页面A的pagesource,直到我刷新页面。我如何清除会话,使$_SESSION['pagesource']对两个页面都可用并且为真?

我在两个页面上都使用session_start();

谢谢

试试这个,在页面B(或任何页面)的顶部

<?php
    //Remember to start the session on each page
        session_start();
    //Unsets all session variables without discretion - ony use if strictly necessary
        session_unset(); 
    //Destroys the session, again without discretion - ony use if strictly necessary
        session_destroy();
    //Typical way to unset any variable
        unset($_SESSION['pagesource']);
    //Create a new $_SESSION['pagesource'] session variable and set it equal to what get_the_page_title() returns
        $_SESSION['pagesource'] = get_the_page_title();
        //do anything you want with the page title
    exit();
?>

我几乎涵盖了所有的基础;试试这个,如果可以的话,我们可以改进它