markcunningham07 Posted August 10, 2010 Share Posted August 10, 2010 Hi, <?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views']+ 1; else $_SESSION['views'] = 1; echo "views = ". $_SESSION['views']; session_destroy(); ?> above code asically shows howmany times user refresh the page. is it possible to return counting to 1 after user refresh page 8 times. for example : User comes for the first time. Script gives 1 as output after user refresh the page. Script gives 2 as output it goes so on. i want code to return to 1 after it been refresh 8 times. how can i do that. Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 10, 2010 Share Posted August 10, 2010 First question: why are you calling session_destroy()? Remove that. session_start(); if (isset($_SESSION['views']) && ($_SESSION['views'] $_SESSION['views'] = $_SESSION['views']+ 1; } else { $_SESSION['views'] = 1; } echo "views = ". $_SESSION['views']; Quote Link to comment Share on other sites More sharing options...
markcunningham07 Posted August 10, 2010 Author Share Posted August 10, 2010 <?php session_start(); if (isset($_SESSION['views']) && ($_SESSION['views] < 9)) { $_SESSION['views'] = $_SESSION['views']+ 1; } else { $_SESSION['views'] = 1; } echo "views = ". $_SESSION['views']; ?> Hi, i am getting following error on above script Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/marko/public_html/test.php on line 5 Quote Link to comment Share on other sites More sharing options...
gizmola Posted August 10, 2010 Share Posted August 10, 2010 Yes, I had a typo that I corrected, but i guess you copied my code before I edited it. After the && ($_SESSION['views] I left out the end quote inside the array element. Should be $_SESSION['views'] Quote Link to comment Share on other sites More sharing options...
markcunningham07 Posted August 10, 2010 Author Share Posted August 10, 2010 Sorry my fault, your code is perfect, thank you for lightening fast post Quote Link to comment 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.