Facing some problem while accessing session variable in another web page
i have tried using jquery to refresh the page which create the session(data.php) also the database connection and sql query works fine, tested them independently.
test.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<body>
<div id="show"> </div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function () {
$('#show').load('data.php') // reloades data.php repetedly
}, 1000);
});
</script>
<?php echo $_SESSION["id"]; ?>
</body>
</html>
data.php
<?php
session_start();
$conn = new mysqli("localhost","id6207501_datausername","123456789","id6207501_dataname");
if ($conn->connect_error) {
die("Connection error: " . $conn->connect_error);
}
$result = $conn->query("SELECT status,id FROM logs order by id desc limit 1");
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$_SESSION["id"]=$row['id'];
$_SESSION["status"]=$row['status'];
}
}
?>
i expect the test.php to print the value of session variable $_SESSION["id"]
, which it does not.