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?