douyan4470 2016-06-02 18:29
浏览 28

我需要帮助理解Session / Cookie数据。

I'm moving some features of an existing site over to a new site for a client. A couple of the things they are using in the existing site are new to me - namely session data and cookies. I think I have found all of the code that is working with these two things, but when I move the code into the new site, I get errors. This is the code:

//* Store Session information
function store_session_information() {
    $nameKey = 'OnTracUserInfo_Name';
    $districtNameKey = 'OnTracUserInfo_DistrictName';
    $districtCodeKey = 'OnTracUserInfo_DistrictCode';
    $schoolKey = 'OnTracUserInfo_School';
    $emailKey = 'OnTracUserInfo_Email';
    $tokenKey = 'OnTracUserInfo_Token';
    $setAtTimestampKey = 'OnTracUserInfo_setAtTimestampKey';
    $hitAtTimestampKey = 'OnTracUserInfo_hitAtTimestampKey';
    $incrementKey = 'OnTracUserInfo_incrementKey';
    $hitCountKey = 'OnTracUserInfo_hitCountKey';

if (empty($_SESSION[$hitCountKey])){
    $_SESSION[$hitCountKey] = 1;
}
else
{
    $_SESSION[$hitCountKey] = $_SESSION[$hitCountKey] + 1;
}
$_SESSION[$hitAtTimestampKey] = date('Y-m-d H:i:s');

if(
    $_REQUEST[$nameKey] != ""
    || $_REQUEST[$districtNameKey] != ""
    || $_REQUEST[$districtCodeKey] != ""
    || $_REQUEST[$schoolKey] != ""
    || $_REQUEST[$emailKey] != ""
    || $_REQUEST[$tokenKey] != ""
) {
    $_SESSION[$nameKey] = $_REQUEST[$nameKey];
    $_SESSION[$districtNameKey] = $_REQUEST[$districtNameKey];
    $_SESSION[$districtCodeKey] = $_REQUEST[$districtCodeKey];
    $_SESSION[$schoolKey] = $_REQUEST[$schoolKey];
    $_SESSION[$emailKey] = $_REQUEST[$emailKey];
    $_SESSION[$tokenKey] = $_REQUEST[$tokenKey];

    $_SESSION[$setAtTimestampKey] = date('Y-m-d H:i:s');
    if (empty($_SESSION[$incrementKey])){
        $_SESSION[$incrementKey] = 1;
    }
    else
    {
        $_SESSION[$incrementKey] = $_SESSION[$incrementKey] + 1;
    }

}
}

//* Write session variables to JS variables
add_action( 'wp_head', 'set_js_session_variables');

function set_js_session_variables() {
    $nameKey = 'OnTracUserInfo_Name';
    $districtNameKey = 'OnTracUserInfo_DistrictName';
    $districtCodeKey = 'OnTracUserInfo_DistrictCode';
    $schoolKey = 'OnTracUserInfo_School';
    $emailKey = 'OnTracUserInfo_Email';
    $tokenKey = 'OnTracUserInfo_Token';
    $setAtTimestampKey = 'OnTracUserInfo_setAtTimestampKey';
    $hitAtTimestampKey = 'OnTracUserInfo_hitAtTimestampKey';
    $incrementKey = 'OnTracUserInfo_incrementKey';
    $hitCountKey = 'OnTracUserInfo_hitCountKey';

    store_session_information();

    echo '
    <script type="text/javascript">
        var onTracUserInfo = {};
        onTracUserInfo.name = \'' . $_SESSION[$nameKey] . '\';
        onTracUserInfo.districtname = \'' . $_SESSION[$districtNameKey] . '\';
        onTracUserInfo.districtcode = \'' . $_SESSION[$districtCodeKey] . '\';
        onTracUserInfo.school = \'' . $_SESSION[$schoolKey] . '\';
        onTracUserInfo.email = \'' . $_SESSION[$emailKey] . '\';
        onTracUserInfo.token = \'' . $_SESSION[$tokenKey] . '\';
        onTracUserInfo.setAtTimestamp = \'' . $_SESSION[$setAtTimestampKey] . '\';
        onTracUserInfo.increment = \'' . $_SESSION[$incrementKey] . '\';
        onTracUserInfo.hitAtTimestamp = \'' . $_SESSION[$hitAtTimestampKey] . '\';
        onTracUserInfo.hitCount = \'' . $_SESSION[$hitCountKey] . '\';
    </script>
    ';
}

The error message I receive is this: Undefined index: OnTracUserInfo_Name

for every one of these:

$nameKey = 'OnTracUserInfo_Name';
$districtNameKey = 'OnTracUserInfo_DistrictName';
$districtCodeKey = 'OnTracUserInfo_DistrictCode';
$schoolKey = 'OnTracUserInfo_School';
$emailKey = 'OnTracUserInfo_Email';
$tokenKey = 'OnTracUserInfo_Token';
$setAtTimestampKey = 'OnTracUserInfo_setAtTimestampKey';
$hitAtTimestampKey = 'OnTracUserInfo_hitAtTimestampKey';
$incrementKey = 'OnTracUserInfo_incrementKey';
$hitCountKey = 'OnTracUserInfo_hitCountKey';

I guess I must be missing something that is setting the items like "OnTracUserInfo_Name" to some index number. But I don't have a clue in the world where that info could or should be coming from. Am I missing an obvious piece here that someone with more experience could instantly spot?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行