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

Link to comment
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.