News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Page View Counter

Started by aldo, January 21, 2008, 12:15:52 AM

Previous topic - Next topic

aldo

Link to Mod

This is a simple modification, Not my first, but my first released to SMF.

What does this mod do? It simply counts how many page views you have gotten so far... it is a simple function. It only does puts the function in the default theme but can be very easily added to any other theme.
Simply add

Pageview_counter();

In the footer where you would like it to appear.
Enjoy it.

shadow82x

It's finally approved aldo. ;)
Colin B
Former Spammer, Customize, & Support Team Member

ALEJO

it works fine, but everytime i enter in a forum and go back to forum index it counts me like a visit, can u fix that? :) thx
solo el mas paranoico sobrevive

aldo

Its a page view counter ;) I am going to probably work on a unique counter soon ;)

ALEJO

Quote from: aldo on January 21, 2008, 04:16:47 PM
Its a page view counter ;) I am going to probably work on a unique counter soon ;)
that would be great, cause is a simple (for coders not for me) thing that noone has done for smf :) i wait ur work ;)
solo el mas paranoico sobrevive

Apllicmz




karlbenson

Aldo, there is an issue with your mod that will PREVENT the counter from accurately displaying the information.

Between your queries to 'grab the current counter' and 'update the counter', multiple people could be running the same queries.
So the users might all get the value 1000, and each try to set it as 1001.

The solution is to just Update (it also saves a query)


function pageview_count()
{
// Access Globals
global $db_prefix, $modSettings;

// Query to update (without reading the value)
db_query("
UPDATE {$db_prefix}settings
SET value= value + 1
WHERE variable='pageview_counter'
LIMIT 1
",__FILE__,__LINE__);
// We already have the pageview counter stored, so just increase it by 1
$modSettings['pageview_counter']++;
}


I've separated the showing of the variable into a separate function, just in case the user wants to show it somewhere else.
Because using your function, if they put it on multiple places on the page, it would count multiple times.


function pageview_show()
{
// Access Globals
global $modSettings, $txt;

echo '<span style="text-align: center;">' . $txt['pageviews'] . $modSettings['pageview_counter'] .'</span>';
}

aldo

Oh thanks again :) I will fix it up tomorrow, thanks again

jossanaijr


ne.miguelito

of the one not to place the Total Page equal Views to the Total page views of forum in Statistics Center, e that the value is always the same

Angelotus

Dit you fix this up yet aldo?

aldo

No sorry, just got back from school... I am a bit busy with some homework and some other business, I should get it up by tonight ;)

samurai-lupin

Hello,

I was trying to use your fine mod but for some unknown reason my page view counter does not count the hist but only displays "1" all the time?! My forum is located at www.detektorforum.de/smf

Do you have any ideas what could be wrong? Thank you!

Mystiquo

it's possible view the members that look a post?

kota069

How do you reset it to Zero? (Or can you?)

bmwsport

Hey guys - how can I get this to appear at the top of the site where your info is...

135 messages, 0 are new
Show unread posts since last visit.
Show new replies to your posts.
Total time logged in: 6 days, 20 hours and 28 minutes.

I'd like this counter directly under here, because there is room, and may get more registrations...any way?  I've toyed with it a bit, but no luck yet...

aldo

So you want the page view count to appear under there? And you think it might help get more registrations?

Advertisement: