我将现有网站的某些功能移动到客户端的新网站。他们在现有网站中使用的一些东西对我来说是新的 - 即会话数据和cookie。我想我已经找到了所有使用这两件事的代码,但是当我将代码移动到新网站时,我会遇到错误。这是代码:
//* 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>
';
}
我收到的错误信息是: 未定义的索引:OnTracUserInfo_Name
每一个:
$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';
我想我必须遗漏一些设置像&#34; OnTracUserInfo_Name&#34;一些索引号。但我不知道世界上哪些信息可能或应该来自哪里。我在这里错过了一个明显的部分,那些有更多经验的人可以立即发现?