Sessions
I have a problem with session, I am using the following script script with sessions functionality but I am having the problem that as long as I refresh the session concept work fine, cookie sends the PHPSESSID val(val of count increments that is what the script does if the session exists),
but simeltaneously when I run a new instance of the browser and type the URL for php script again then it seems as if PHP creates a new session for me ( and takes count 0 i.e the session does not exist and a new sesssion is created, I have not closed the earlier browser).
I will be very thankful to you if you can help me to understand why it does not send the PHPSESSID(why there is a new sesssion everytime when I have this URL run in new instance of browser and not the same session).
<?php
// Initialize a session. This call either creates
// a new session or re-establishes an existing one.
session_start();
// If this is a new session, then the variable
// $count will not be registered
if (!session_is_registered("count"))
{
session_register("count");
session_register("start");
$SESSION["count"] = 0;
$SESSION["start"] = time();
}
else
{
$_SESSION["count"]++;
}
$sessionId = session_id();
?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>Session State Test</title>
</head>
<body>
<p>This page points at a session
(<?php echo $sessionId; ?> )
<br>count = <?php echo $SESSION["count"];?>.
<br>start = <?php echo $SESSION["start"];?>.
<p>This session has lasted
<?php
$duration = time() - $_SESSION["start"];
echo "$duration";
?>
seconds.
</body>
</html>