Jump to content


Visitors Counter


6 replies to this topic

#1 affenmunkEY

    Jedi In Training

  • Members
  • PipPip
  • 357 posts
  • Gender:Male
  • Location:Bielefeld, Germany

Posted 28 July 2008 - 02:51 AM

Hi, I'm looking for a visitors counter that looks like the one under the login on the right on this page:

http://www.redeyes-gaming.de

I have counter.php they've used as well as it's all from a free Clan CMS but I'm guessing I can't use it on a page I haven't got the CMS installed on.. Can anyone help? This is the code by the way:

Also, I wouldn't want a viewing of online guests/registered users as that wouldn't be of interest on this website.

$pagebg=PAGEBG;

$border=BORDER;

$bghead=BGHEAD;

$bgcat=BGCAT;

$bg1=BG_1;

	

$date = date("d.m.Y", time());

$dateyesterday = date("d.m.Y", time()-(24*3600));

$datemonth = date(".m.Y", time());

	

$ergebnis=safe_query("SELECT hits FROM ".PREFIX."counter");

$ds=mysql_fetch_array($ergebnis);

$us = mysql_fetch_array(safe_query("SELECT count(userID) FROM ".PREFIX."user"));

$us=$us[0];



$total=$ds[hits];

$dt = mysql_fetch_array(safe_query("SELECT count FROM ".PREFIX."counter_stats WHERE dates='$date'"));

if($dt[count]) $today = $dt[count]; else $today = 0;



$dy = mysql_fetch_array(safe_query("SELECT count FROM ".PREFIX."counter_stats WHERE dates='$dateyesterday'"));

if($dy[count]) $yesterday = $dy[count]; else $yesterday = 0;



$month=0;

$monthquery = safe_query("SELECT count FROM ".PREFIX."counter_stats WHERE dates LIKE '%$datemonth'");

while($dm=mysql_fetch_array($monthquery)) {

 $month = $month+$dm[count];

}



$online = mysql_num_rows(safe_query("SELECT time FROM ".PREFIX."whoisonline"));

	

$guests = mysql_num_rows(safe_query("SELECT ip FROM ".PREFIX."whoisonline WHERE userID=''"));

$user = mysql_num_rows(safe_query("SELECT userID FROM ".PREFIX."whoisonline WHERE ip=''"));

$useronline = $guests + $user;

	

if($user==1) $user_on='1 user';

else $user_on=$user.' users';	

	

if($guests==1) $guests_on='1 guest';

else $guests_on= $guests.' guests';

	

eval ("\$stats = \"".gettemplate("stats")."\";");

echo $stats;

?>

Edited by Mr. Matt, 28 July 2008 - 08:49 AM.


#2 Tyson D

    Young Padawan

  • Members
  • Pip
  • 85 posts
  • Gender:Male
  • Location:Canada

Posted 28 July 2008 - 09:20 AM

If you do not have this CMS, you may want to consider building your own statistics tracking mechanism. It wouldn't be too tricky. Here is a simple way that you could do it...

Create a table in your database, call it something like site_stats or whatever you'd like, make a column for id (in case you'd ever want to relate it to another table), visitor_ip, and date.

On a page load you could have a script that queries the database using the ip of the user viewing and a date format that just includes the month, day and year. Your query could be something like this...

$today = date("F j Y"); // Format: Month day yyyy
 $query = "SELECT visitor_ip, date FROM site_stats WHERE visitor_ip = '$_SERVER[REMOTE_ADDR]' AND date = '$today'";
 $result = mysql_query($query);

Then if the result was empty you'd add the information to the table because it would mean it was the first visit from the user on the particular day!

Then to get your stats you'd just do some count commands where your queries are based on dates. I'm kind of new to MySQL so there is probably a more efficient and better way of doing it, but this way seems like it could work and give you a pretty good unique visitors count, if you don't want a unique count then simply don't do the query and just add the information in, but that's going to inflate your numbers big time...

Good luck!

Edited by TysonD, 28 July 2008 - 09:21 AM.


#3 affenmunkEY

    Jedi In Training

  • Members
  • PipPip
  • 357 posts
  • Gender:Male
  • Location:Bielefeld, Germany

Posted 28 July 2008 - 11:18 AM

Thx for the quick, reply.. do you know of any tutorial sites I could use to figure this one out, becuase I'm not sure how to do all this... Or does anyone know of a ready-code?

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 July 2008 - 12:10 PM

Yes, pixel2life :)
http://www.pixel2life.com/tutorials/php_co...tion_and_stats/

#5 Tyson D

    Young Padawan

  • Members
  • Pip
  • 85 posts
  • Gender:Male
  • Location:Canada

Posted 28 July 2008 - 12:11 PM

Hey affenmunkEY,

I just coded up a package for you over lunch. I've included a readme and stuff in it and I made an install page for you. It should be pretty configurable, I made it very basic.

It has functionality to display viewers from today, yesterday, this month and all time. All visitors are unique and can only be logged once per day (by ip address). You can add your own functions if you want more detailed stats and you can mess around with the code however you like. It should easily integrate into anything you have going already.

See the attached zip folder for the files. Read the Readme!

Cheers!

Attached Files



#6 Tyson D

    Young Padawan

  • Members
  • Pip
  • 85 posts
  • Gender:Male
  • Location:Canada

Posted 28 July 2008 - 12:14 PM

View Postrc69, on Jul 28 2008, 12:10 PM, said:


Whoops, didn't realize you were replying at the same time!

#7 affenmunkEY

    Jedi In Training

  • Members
  • PipPip
  • 357 posts
  • Gender:Male
  • Location:Bielefeld, Germany

Posted 28 July 2008 - 12:18 PM

Sweet stuff guys, thanks a lot :) Tyson seems to be a new friendly active member to the board :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users