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. Link to comment https://forums.phpfreaks.com/topic/210298-work-around-with-session/ 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']; Link to comment https://forums.phpfreaks.com/topic/210298-work-around-with-session/#findComment-1097390 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 Link to comment https://forums.phpfreaks.com/topic/210298-work-around-with-session/#findComment-1097397 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'] Link to comment https://forums.phpfreaks.com/topic/210298-work-around-with-session/#findComment-1097399 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 Link to comment https://forums.phpfreaks.com/topic/210298-work-around-with-session/#findComment-1097400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.