Search code examples
asp-classic

Count the number of pages using asp and javascript language


I am trying to create a cookie and also counting the number of times i am visiting that page. Here is the code:

<%
var visits=0;
visits=Request.Cookies("count");

if(visits="0") {
    Response.Cookies("count")=1;
    Response.Write("Welcome! You Have Visited This Page First  Time");
}
else {
    Response.Cookies("count")+=1;
    Response.Write("You Have visited this page" + Request.Cookies("count"));
    if(visits="1") {
        Response.Write(" time before");
    }
    else {
        Response.Write(" times before");
    }
}
%>

I am getting the output as:

Welcome! You Have Visited This Page First Time

Even if I try refresh the page i am getting the same above statement as the output. Thanks in advance for help


Solution

  • You have to use == to compare two values. And you are comparing string and int, but that's wrong.

    Try this:

    if(visits==0) {