Hit Counter.

tpounds

New Member
Messages
36
Reaction score
0
Points
0
I need help on inserting a hit counter on Dreamweaver. I need to know how many people have gone to my site.

Please help me with the script, or give me one. I don't know PHP D:
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
i don't know if you're gonna be using mysql or a file to count the users, but i'll post below. the mysql one is assuming you've already got a connection open.

PHP:
<?php
// Hit counter stored to file

$loc = '/home/username/counter.txt';
$fp = fopen ($loc, 'w+');
$hits = fread ($fp, filesize($loc));
$hits++;
fwrite ($fp, $hits);
fclose ($fp);

echo 'Hits: ',$hits;

?>

PHP:
<?php
// Hit counter stored to database

list($hits) = mysql_fetch_row(mysql_query('SELECT hits FROM counter');
$hits++;
mysql_query('UPDATE counter SET hits=\''.$hits.'\' LIMIT 1');

echo 'Hits: ',$hits;
?>
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I Use a hit counter but also visitor history, which tells me more about each visit: stored to MySQL(Table 'LOG'), so that I can report on it.

This is the php file "sniffer.php" which I put into an incude folder.

You'll have to put in your own connection and database selection.

PHP:
<!--Sniffer Script -->
<?php require_once ($_SERVER["DOCUMENT_ROOT"].'/Connections/freecrm.php'); ?>
<?php 
//connection
//database selection

  	<?php
  	$userloggedin=$HTTP_SESSION_VARS['MM_Username'];//take username from session if you are using it.
  	$ip=$_SERVER['REMOTE_ADDR'];//get ip address
  	$when = time();//get time page was hit
	$clientbrowser = getenv(HTTP_USER_AGENT);//get system and browser info
	$referer = getenv(HTTP_REFERER);// get refering page i.e. where it came from
		function getAddress()
		{
		$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
		return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		}
	$clienturl=getAddress();//call address function above to get URL visited
	$clienthost=gethostbyaddr($_SERVER['REMOTE_ADDR']);//get hostname
	$clientlanguage=$_SERVER["HTTP_ACCEPT_LANGUAGE"];// get language
	?>
<!--end sniffer script -->
<!--Start of sniffer insert -->
	<?php
	mysql_query("
	INSERT INTO LOG (IP, BROWSER, VISDATETIME, REFERAL, URL, LANGUAGE, HOST) VALUES('$ip', '$clientbrowser', '$when', '$referer', '$clienturl' ,'$clientlanguage', '$clienthost')
	") or die(mysql_error()); //insert record into db
	?>
<!--End of sniffer insert -->

When this is saved, just include this in every page you want to track. (I put it into a header include so its always on every page I put a header into.)

PHP:
<?php include("sniffer.php");?>

You can then have a report page to echo this data however you want. It also tracks bots.
 
Top