Hi all
can anybody help me how to include a hit counter in the site. Is there any open source available please let me know to download it
thanks in advance
Hi all
can anybody help me how to include a hit counter in the site. Is there any open source available please let me know to download it
thanks in advance
hi,
what site do you refere to as "the site" and search google for for a free hit counter, also they are quite simple to make
Hi benracer
can you tell me any best one
Just make one, they're quite simple. You'll need a database or a file that you can write to. Then, for a simple hit counter, all you do is put in a code snippet at the top of every page you want to count - have it read in the current count from the file/db, add one to it, write it to the file/db, then display the updated total to the visitor.
i use google analytics as this shows you the rough location of your visitor, the search querys used to find the page, countries... this does not show on the page its self so its more of an hidden way of you finding out. The script that i made, this counts the unique page hits not each time the page is viewed.
$session=session_id();
$time=time();
$ip= $_SERVER['REMOTE_ADDR'];
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE ip='$ip'";
$result=mysql_query($sql);
if($count=="1"){
exit;
}if($count=="0"){
$sql1="INSERT INTO $tbl_name(session, time, ip)VALUES('$session', '$time', '$ip')";
$result[0]=mysql_query($sql1);
}
echo "<br>Visits - ";
$sql = mysql_query("SELECT COUNT(*) FROM user_online");
$results = mysql_fetch_row($sql);
echo "$results[0]";[echo "<br>Visits - ";
$sql = mysql_query("SELECT COUNT(*) FROM user_online");
$results = mysql_fetch_row($sql);
echo "$results[0]";
hi benracer
thank you for your help
If you've tested that code and it works, then please don't forget to mark this resolved.
Also, benracer: you don't need to put double-quotes around:
mysql_connect("$host", "$username",//...
And other such things. $host would be fine in that instance. Single-quotes will not evaluate variables - '$host' would be literally printed as $host, double-quotes will evaluate variables - "$host" becomes localhost or similar - and just $host in the function will be evaluated to localhost, as if you'd passed mysql_connect('localhost'). Just a note.
Note that certain proxy users (e.g. at some schools, AOL users, etc.) will have the same external IP.
Also, I'm not sure why the session ID is being stored in the DB, but if you're truly going for unique hits based on IP, you could add a UNIQUE index on the IP column, get rid of the first SELECT query altogether, and just run the INSERT query.
this script is just copied from my ecommerce site, i use it to time how long it takes between the first visit to the time of the order. I just copied it from there in a rush thanks brad
Hi benracer,
I found a good script from phpjunkyard
//graphcount.php
<?php
/*******************************************************************************
* Title: PHP graphical hit counter (PHPGcount)
* Version: 1.1 @ October 26, 2007
* Author: Klemen Stirn
* Website: http://www.phpjunkyard.com
********************************************************************************
* COPYRIGHT NOTICE
* Copyright 2004-2007 Klemen Stirn. All Rights Reserved.
*
* This script may be used and modified free of charge by anyone
* AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
* By using this code you agree to indemnify Klemen Stirn from any
* liability that might arise from it's use.
*
* Selling the code for this program, in part or full, without prior
* written consent is expressly forbidden.
*
* Obtain permission before redistributing this software over the Internet
* or in any other medium. In all cases copyright and header must remain
* intact. This Copyright is in full effect in any country that has
* International Trade Agreements with the United States of America or
* with the European Union.
*******************************************************************************/
// SETUP YOUR COUNTER
// Detailed information found in the readme file
// URL of the folder where script is installed. INCLUDE a trailing "/" !!!
$base_url = 'http://www.yourwebsite.com/gcount/';
// Default image style (font)
$default_style = 'web1';
// Default counter image extension
$default_ext = 'gif';
// Count UNIQUE visitors ONLY? 1 = YES, 0 = NO
$count_unique = 0;
// Number of hours a visitor is considered as "unique"
$unique_hours = 24;
// Minimum number of digits shown (zero-padding). Set to 0 to disable.
$min_digits = 0;
#############################
# DO NOT EDIT BELOW #
#############################
/* Turn error notices off */
error_reporting(E_ALL ^ E_NOTICE);
/* Get page and log file names */
$page = input($_GET['page']) or die('ERROR: Missing page ID');
$logfile = 'logs/' . $page . '.txt';
/* Get style and extension information */
$style = input($_GET['style']) or $style = $default_style;
$style_dir = 'styles/' . $style . '/';
$ext = input($_GET['ext']) or $ext = $default_ext;
/* Does the log exist? */
if (file_exists($logfile)) {
/* Get current count */
$count = trim(file_get_contents($logfile)) or $count = 0;
if ($count_unique==0 || $_COOKIE['gcount_unique']!=$page) {
/* Increase the count by 1 */
$count = $count + 1;
$fp = @fopen($logfile,'w+') or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!');
flock($fp, LOCK_EX);
fputs($fp, $count);
flock($fp, LOCK_UN);
fclose($fp);
/* Print the Cookie and P3P compact privacy policy */
header('P3P: CP="NOI NID"');
setcookie('gcount_unique', $page, time()+60*60*$unique_hours);
}
/* Is zero-padding enabled? */
if ($min_digits > 0) {
$count = sprintf('%0'.$min_digits.'s',$count);
}
/* Print out Javascript code and exit */
$len = strlen($count);
for ($i=0;$i<$len;$i++) {
echo 'document.write(\'<img src="'.$base_url . $style_dir . substr($count,$i,1) . '.' . $ext .'" border="0">\');';
}
exit();
} else {
die('ERROR: Invalid log file!');
}
/* This functin handles input parameters making sure nothing dangerous is passed in */
function input($in) {
$out = htmlentities(stripslashes($in));
$out = str_replace(array('/','\\'), '', $out);
return $out;
}
?>
which i am attaching the zip file along with this mail please find it very easy and useful for every template based website.
Thanks friends for your help
I found a good script from phpjunkyard
I would warn that the author is not aware of why he gets notices with his script, and thus turns them off like an ostrich sticking its head in the sand. The script also assumes that magic_quotes_gpc is set to on, which is no longer the default setting and is in fact considered bad practice.