duanhui5344 2014-02-20 21:43
浏览 34

PHP会话变量并不总是在Wordpress中更新

I'm trying to pass the URL of a page to a session variable, so i can use it in a login plugin. The login plugin only refers to the profile page, but it won't refer to the previous page the user was on. I've tried using wp_get_referer(); in the login plugin itself, but because the login form sends it to a different page, the previous page according to wordpress is the login page.

In order to do this i first of all put the following in my functions.php:

add_action('init', 'myStartSession', 1);

function myStartSession() {
    if(!session_id()) {
        session_start();
    }
}

In my header.php, I check if the user is on the login (profiel) page or not. If he isn't, the current URL should be placed in a session variable. If he is, the session variable shouldn't change. To do this, i use the following code, right below the start of <body>:

<?php
    if (!is_page('profiel')) {
           $_SESSION["refurl"] = $_SERVER['HTTP_REFERER'];
       }
?>

However, this only seems to work sometimes. On the 'profiel' page, where the login form is, I added <?php echo 'session' .$_SESSION["refurl"]; ?> to check wether or not the previous URL has been saved to the session variable. The problem is that a lot of the times it refers to my home url, instead of the page previously visited. What am i doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 r语言神经网络自变量重要性分析
    • ¥15 基于双目测规则物体尺寸
    • ¥15 wegame打不开英雄联盟
    • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢