Webmastersite.net
Register Log In

Page counter
for member

Comments on Page counter

Jumpin Jack


Usergroup: Customer
Joined: Jan 13, 2005

Total Topics: 23
Total Comments: 50
Posted Feb 27, 2006 - 7:51 PM:

I want to add a page counter to my members profile page. that is stored under a custom field {MEMBERVIEWS}. I want to be able to display or sort member profile page views in toplists and other areas of the site. Something similar to the {CATVIEWS} counter. Is there currently a way to do this?
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Mar 01, 2006 - 6:17 PM:

A clumsy but workable way to do it would be to add a member field 'views' and then stick this php in the profile template:
<?php global $amem; $amem->views += 1; $amem->update('views'); ?>


Making it count only unique views would be tricker, but you could set a cookie and test for it in the same profile template area.
Jumpin Jack


Usergroup: Customer
Joined: Jan 13, 2005

Total Topics: 23
Total Comments: 50
Posted Mar 02, 2006 - 9:48 PM:

How do I set a cookie and test for it
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Mar 02, 2006 - 10:14 PM:

You can use WSN's makecookie('cookiename', 'value'); function, or just http://www.php.net/setcookie . To test, if ($_COOKIE['cookiename']) { do stuff }
Of course it goes without saying that if you're adding new functionality it helps to know php.
Jumpin Jack


Usergroup: Customer
Joined: Jan 13, 2005

Total Topics: 23
Total Comments: 50
Posted Mar 03, 2006 - 6:06 AM:

Thanks, this is what I did and it works. It expires the cookie after 24hrs
 
<?
makecookie('{MEMBERNAME}', '{MEMBERID}', time()+(86400));
if (!$_COOKIE['{MEMBERNAME}'])
{
global $amem;$amem->views += 1; $amem->update('views');
}
?>

Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Mar 04, 2006 - 8:26 PM:

It's better to set a cookie name that doesn't change (say 'profilevisit'), both to reduce potential conficts and so that when a guest registers they don't suddenly get counted again.
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



This thread is closed, so you cannot post a reply.