Jump to content

page counter, setting a session variable


woodplease

Recommended Posts

i'm creating a page counter which updates a value in a database each time the page is loaded.

I'm trying to make it so that it checks to see if a session has been set, if not, it updates the database, and then sets the session. This way it wont update every time someone refreshes the page.

$id=$_GET['id'];
if(!isset($_SESSION[$id])){
$_SESSION[$id]=	$id;
$views = $row['views'] + 1;
$update_views=mysql_query("UPDATE topic SET views='".$views."' WHERE topic_id='".$id."'")

 

i want to set the session variable as that of the page id ($id)

The problem is that it keeps updating the database everytime the page is reloaded. I'm not sure if i'm setting the session variable correctly.

Any ideas would be great

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/225868-page-counter-setting-a-session-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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