Jump to content

Visitor Count + Active Visitor?


awiiya

Recommended Posts

Hello again! Another question for the Oak Log.

I was wondering if it would be possible to add a visitor counter (and I don't mean one of those horrendous neon colored ones usually offered online. Something more classy, and MD fitting? Tan toned) and an active visitor notifier?

So essentially at the bottom of the main page you would be able to see how many people are reading it, or how many people have read it. Does that make sense?

Thank you.

Awi

Link to post
Share on other sites

That should be possible already, at least in my head it is.

If you set a variable to be 0, then run +1 on it, and display the....hmm lemme see if i can write it


[code]
@va==0 //sets variable

if (uv(mp) => 2){ //cos i cant think of how else to do this
@va + 1 = @vb; //adds one on when page visited
}

echo "You are the " @vb " visitor"; //prints the number of visitors
[/code]


or something....doubt this works, but basic idea anyway

Link to post
Share on other sites

Grido, you're on the right track. You are only missing the persistent storage.

Indiscriminantly count visitors:
[code]//get vistor count from storage
retrieve(@vv);
//check to see if the counter has previously been set
if(isset(@vv) && (@vv > 0)){
//increase counter by 1
++@vv ;
}else{
//initiliaze counter (initialize to 0 if you don't want to count your first view of the clickable)
@vv = 1;
}
//save the counter to storage
@store(@vv);
//output the information you want
echo "There have been " . @vv . " visitors here";[/code]

Here's an example of counting unique visitors and number of visits by each player, based on the player id:
[code]//get vistors from storage
retrieve(@vv);
//see if array is already initialzed and if user has already visited
if(@vv != null && (@vv['uv(id)'] > 0)){
//increment the player's visits
++@vv['uv(id)'];
echo "You have visited here " . @vv['uv(id)'] . " times<br />";
}else{
//initiliaze the player's visists
@vv = array('uv(id)' => 1);
echo "This is your first visit<br />";
}
//save the visitors to storage
@store(@vv);
echo "There have been " . count(@vv) . " unique visitors here";[/code]

Regarding the styling, wrap the output in a div and style as you desire.

Link to post
Share on other sites

After a long talk and some coding, we produced the following:

[code]
@vo = mds_storage("OAKSTORYLOG", "toau"); //retrieving the int label for the variable
if(@storage[@vo] == null){//initializing the stored array if not already done.
@storage[@vo] = array(0, array());
}
@storage[@vo][0]++; //increment the general counter (total people)
if(@storage[@vo][1][uv(id)] != null && (@storage[@vo][1][uv(id)] > 0)){//check if it is instantialized or not
@storage[@vo][1][uv(id)]++;//increment personal counter
}else{
@storage[@vo][1][uv(id)] = 1;//if the personal counter doesn't exist, create one.
}
//replacing things in the content panel.
@content[1] = str_replace("[[NAME]]", uv(name), @content[1]); //replaces [[NAME]] with name of current viewer
@content[1] = str_replace("[[COUNT]]", @storage[@vo][0], @content[1]); //replaces [[COUNT]] with total visitors
@content[1] = str_replace("[[UNIQUE]]", count(@storage[@vo][1]), @content[1]);//replaces [[UNIQUE]] with unique visitors
@content[1] = str_replace("[[YOURVISITS]]", @storage[@vo][1][uv(id)], @content[1]); //replaces [[YOURVISITS]] with your personal count.
echo @content[1];[/code]

It keeps track of three things:
1. Total visits
2. Unique visits
3. Your personal visits.

In the Content panel, make sure you have something like the following:

[code]
<!-- content separator -->
<br><br><br><br>
Hello [[NAME]]<br><br>
There have been [[COUNT]] visits in total, and [[UNIQUE]] people have visited.<br><br>
You have visited [[YOURVISITS]] times.
[/code]

Link to post
Share on other sites

Archived

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

  • Forum Statistics

    16,149
    Total Topics
    176,377
    Total Posts
  • Recently Browsing

    No registered users viewing this page.

  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...