Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I count a page views?

How can I count page views so that when I go and refresh the page the counter doesn't consider it as new view?

like image 821
Enas Avatar asked Sep 12 '25 02:09

Enas


1 Answers

1-declare a session for each user

2- declare application variable for the page visited

and after you start the session

check if page visited like the following:

on the user login page or homepage:

Session["pageVisited"] = false;

when user visit the page write in the code behind:

if(SESSION["pageVisited"] == false)
{
   APPLICATION["Page1Visited"] = Convert.Toint32(APPLICATION["Page1Visited"]) + 1;
   SESSION["pageVisited"] = true;
}
like image 55
Hiyasat Avatar answered Sep 13 '25 14:09

Hiyasat