Is my following chain is correct?
First I display the client home.php which will create a session and will store inside $_SESSION['name'] = 'random_name' and will Greet end user client:
<?php
session_start();
$_SESSION['name'] = 'random_name';
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Greeting</h1>
<a id="1" href="index.php">link</a>
</body>
</html>
Then I will press on the link which will take me to the second page index.php which will take me to another page which will display for user the value inside$_SESSION['name'] after certain logic inside the page will be executed as described below:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<script src="test.js"> </script>
<title></title>
</head>
<body>
<p id="para"></p>
<input type="button" onclick="checkAuth()" value="submit">
</body>
</html>
Now when I press the button it will activate checkAuth() function inside test.js that will by using AJAX will retrieve from server side(damn.php) the value inside SESSION['name']:
function checkAuth()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response = xmlhttp.responseText;
document.getElementById("para").innerHTML = response;
}
}
xmlhttp.open("POST","damn.php",true);
xmlhttp.send();
}
Now damn.php looks like that:
<?php
session_start();
if (isset($_SESSION['name'])) {
echo $_SESSION['name'];
}
My question is that the easiest way there is to do it in order to display the client the items inside $SESSION is like that?
Is there a simpler way without using javascript at all? Is it also correct to insert session_start() in every page? or only from pages I want to retrieve the SESSION['items']?