PHP会话停止页面重新加载

我目前有一个WP网站,该网站使用PHP来实现PayPal集成(这是一个旧项目,几年后我要回去,因为我手上的时间太多了)。

当前版本 WordPress 5.4.1 PHP 7.1(主机提供程序限制,不是我的)

在旧版本中,用户可以访问PayPal按钮,完成付款后,他们将返回到自定义网址(需要)。在付款过程中,成功付款后,我创建了$ _SESSION ['fromProcess'] =“ true”;和header('Location:customurl')。

在自定义网址页面上,我检查用户来自何处以及是否设置了会话

if ( is_user_logged_in() ) { 

    // logged in 
    if($_SESSION['fromProcess'] == "false"){ 
        //send them back 
        header("Location: https://example.com/error-page/"); 
    } 
    else{ 
        //reset the variable 
        $_SESSION['fromProcess'] = "false"; 
    } 

    $uid = $_SESSION['uid']; 
    $txn = $_SESSION['token']; 

    if( (!isset($_SESSION['uid'])) && (!isset($_SESSION['token'])) ){ 
        header('Location: https://example.com/error-page/') ; 
        //stop executing the script 
        exit(); 
    } 

}

在旧版本中,这似乎工作得很好,但在新的WP,PHP版本中却没有。

有什么方法可以使这项工作生效,还是我需要寻找一种不同的方法?

谢谢