Forum Moderators: coopster
if (isset($_COOKIE['ArticleCookie'])) {
//cookie is set: do nothing
} else {
setcookie("ArticleCookie", "$categoryid-$articleid", time()+3600*24*15);
$views->views($articleid, $categoryid); //views + 1 function
}
This code is at the top of each article page when the page runs. I cannot figure out why it is giving 3 as the value after it shows 1 once I leave the page?
Your help would be appreciated. Thanks in advance.
I will suggest you to put different check points in your code. e.g put an echo in your else {} to see how many times that is echoed. if that line is echoed three times it means your code is called three time. If that is echoed one time then it means your views() function has incrementing by 3 instead of 1.
It turns out incrementing the views value using $views++ was causing the issue. I changeed it to $viewsNew = $views + 1; and the problem went away?
I think there is something else going on here? Perhaps a variable type issue?
Are you sure $views is an integer? ...In your original post, $views appears to be an instance of a class?