PDA

View Full Version : how to count page refresh with sessions?



sukanya.paul
05-08-2007, 01:24 AM
hi i am stuck with a problem frm last few days n not gettin a solution. :(
it seems u can count the number of time a page is refreshed using session and session variables. i.e if i want my page to be refreshed 10 times then i can hv a session variable whose val is set to 10 n then keep decreasing it whn the page is refreshed.whn the val reaches 0 the page can be redirected to another page.is this possible.if yes how to do it?
help wil be appreciated.
thanks

tech_support
05-08-2007, 06:30 AM
Try this:


<?php
session_start();
$mypage = 'index.php';
if (!isset($_SESSION['refresher'])) {
$_SESSION['refresher'] = 10;
}
elseif ($_SESSION['refresher'] <= 0) {
$_SESSION['refresher'] = 10;
header("location:$mypage");
}
else {
$_SESSION['refresher']--;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="10">
<title>Refresher</title>
</head>

<body>
<p><?php echo $_SESSION['refresher']+1; ?> times until redirection.</p>
</body>
</html>