just got help with making my code for pageviews work... and now i would like the pageviews only count 1 for each session / ip.
In my users (news.users) table i have these cells available for use: (tried to set up something earlier that didnt work out so these are not in use)
ip_reg, ip_visit, dtreg, dtvisit, visits, pass
The code i have that is now working looks like this :
//Adds one to the counter
mysql_query("UPDATE news SET posts = posts + 1, published=published, last_edit=last_edit WHERE id=$id");
//Retreives the current count
$count = mysql_fetch_row(mysql_query("SELECT posts FROM news WHERE id=$id"));
//Displays the count on your site print
echo "<label>Viewed: ";
echo $count[0];
echo " times</label>";
?>
Can i use some of the unused cells in users to stop a user from reloading the page to get higher views on a page? And how do i do it :P
Like I suggested I would put the read news articles in the user's session. Try this:
if (!isset($_SESSION['read_news']) || !is_array($_SESSION['read_news'])) {
$_SESSION['read_news'] = array();
}
if (!in_array($id, $_SESSION['read_news'])) {
$_SESSION['read_news'][] = $id;
mysql_query("UPDATE news SET posts = posts + 1 WHERE id=$id");
}
If this doesn't work, you don't have sessions enabled and you should put session_start();
somewhere in the top of your project. Make sure that line is called in each request.