Jump to content

Work around with Session


markcunningham07

Recommended Posts

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

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']; 

<?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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.