I'm not able debug what is wrong with my code. Here is what I'm doing:
For Ajax queries, I have set a session variable: sessiontoken, and I encode and decode to make sure the request is from correct session/page as shown below, below code is present on every page, And then in the javascript I echo this variable and use in ajax call:
My problem is that while the script is working perfectly fine on every page on the local server(xampp), on the live server it is giving problem. When I login on live site, on home page the decoded value is correctly displayed in the javascript function, however when I click on the link to myprofile or go to any other page, the decoded sessiontoken value displays weird characters. Can you please let me know what could be the problem, as on local it is working just fine. thanx.
<?php
session_start();
if(!(isset($_SESSION['id']) && isset($_SESSION['username']))) {
header("location: index.php");
exit();
}
if(!isset($_SESSION['sessiontoken'])) {
$thisRandNum = rand(999999,99999999);
$_SESSION['sessiontoken'] = base64_encode($thisRandNum);
} else {
$thisRandNum = base64_decode($_SESSION['sessiontoken']);
}
?>
<html>
<head>
<script type="text/javascript">
function refreshWall() {
$.post('scripts/refreshlist.php', {thistoken: <?php echo $thisRandNum ?>},
function(data) {
}, "json");
}
</script>
</head>
<body>
</body>
</html>