SilentQ-noob- Posted August 10, 2007 Share Posted August 10, 2007 Hi, I want to make an if statement that counts how many times a page has been refreshed, and every ten times it refreshes I want it to do something. (send an e-mail for example) I'm not sure if I have to use sessions or how to even go about it. I figured out how to make the page refresh every ten seconds, now I just need it to count that . basically this is all I need to be displayed Number of times page has refreshed: n here is a link to a page that kind of has what I'm looking for, I just dont know how to change it to what I want. http://www.dynamicdrive.com/forums/a...p/t-20513.html That link doesnt seem to work- this is what it says there <?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> Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/ Share on other sites More sharing options...
dbo Posted August 10, 2007 Share Posted August 10, 2007 Total refreshes or refreshes by a single user? Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/#findComment-320561 Share on other sites More sharing options...
SilentQ-noob- Posted August 10, 2007 Author Share Posted August 10, 2007 by single user Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/#findComment-320573 Share on other sites More sharing options...
SilentQ-noob- Posted August 10, 2007 Author Share Posted August 10, 2007 so if you close the page,(end session), then open it again the counter starts from 0 Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/#findComment-320574 Share on other sites More sharing options...
SilentQ-noob- Posted August 10, 2007 Author Share Posted August 10, 2007 ok, well I've figured out part of it now- Now the only thing that isnt working is the email part. The message gets sent, but it doesnt display the date, it just says "The Check was performed on " this is the code I have <? session_start(); if (!isset($_SESSION['refresh'])) $_SESSION['refresh']=0; $_SESSION['refresh']++; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="refresh" content="2" /> <title>Untitled Document</title> </head> <body> <? $to = "myemail@gmail.com"; $subject= "System is Working"; $date = $_POST['date']; print date("F d, Y g:iA"); print "<br />"; print "<br />"; echo "Number of times refreshed: "; echo $_SESSION['refresh']; if($_SESSION['refresh'] == 10) { session_destroy(); mail($to, $subject ,"The Check was performed on $date"); } ?> <p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/#findComment-320608 Share on other sites More sharing options...
lemmin Posted August 10, 2007 Share Posted August 10, 2007 Do you have a form Posting to that file with an input that has a name='date'? If not, Change this: $date = $_POST['date']; print date("F d, Y g:iA"); to: print $date=date("F d, Y g:iA"); Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/#findComment-320622 Share on other sites More sharing options...
SilentQ-noob- Posted August 10, 2007 Author Share Posted August 10, 2007 That solved it, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/64300-solved-refresh-count-help/#findComment-320634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.