Page 1 of 1

content complete counter

Posted: Fri Mar 05, 2004 8:07 pm
by squalls_dreams
alright what about this one? what do I do here and what code do I put in my page for this counter?

Code: Select all

<?php 
/* 
3C, by Andrew Walton.   
Under the GPL, see them for a copy of the license. 

NOTE TO ADMIN:  use some artistic freedom with the PageId field.   
You can either have it report a number (like in my system), report the page request, 
report the actual script name, or any of the above. 

CREATE TABLE counter ( 
  PageId int(10) unsigned NOT NULL default '0', 

  Ip varchar(16) NOT NULL default '', 
  Request varchar(255) default NULL, 
  Referer varchar(255) default NULL, 
  Usr_Agent varchar(255) default NULL, 
  Date varchar(30) NOT NULL default '', 
  Time varchar(30) NOT NULL default '', 
  Id int NOT NULL auto_increment, 
  PRIMARY KEY  (Id) 
) TYPE=MyISAM; 

For Commentable Blog users!! 
Use connect2mysql($db) instead of spending the extra lines for the connection routine. 
*/ 

//determines the PageId. 
if (!empty($_POST&#1111;'Id'])) &#123; 
  $Id = $_POST&#1111;'Id']; 
&#125; elseif (!empty($_GET&#1111;'Id'])) &#123; 
   $Id = $_GET&#1111;'Id']; 
&#125; else &#123; 
   $Id = 31415; 
&#125; 
$connex = mysql_pconnect("localhost", "username", "password"); 
mysql_select_database("the database's name"); 
$q="INSERT INTO counter VALUES ('".$Id. 
                "','".$_SERVER&#1111;'REMOTE_ADDR']. 
                "','".$_SERVER&#1111;'REQUEST_URI']. 
                "','".$_SERVER&#1111;'HTTP_REFERRER']. 
                "','".$_SERVER&#1111;'HTTP_USER_AGENT']. 
                "','".date("m-d-Y"). 
                "','".date("H:m:s"). 
                "','')"; 
$r=mysql_query($q) or die("ERROR"); 
//use dberr if using the commentable blog system 
/* not the best way of counting hits if you dont want to include your own hits.   
On request I can help show you how to patch this..   
(Otherwise, it looks good to include all hits ;) 
*/ 
$query="select count(id) from counter"; 
$ret=mysql_query($query); 
while($w=mysql_fetch_array($ret)) &#123; 
  $count=$w&#1111;'count(id)']; 
&#125; 
/* echo is MARGINALLY faster because it does not return a sucess value. */ 
echo "Hits: &#123;$count&#125;"; 
?>

Also what counter is one the main page of this site? which counter is that one cuz I am trying to get mine like that.

Posted: Fri Mar 05, 2004 8:52 pm
by tim
I suggest doing a php/MySQL tutorial...

Instead of asking questions about how a script works, why not attempt yourself to find the understanding...Heres a good, easy tutorial that I promise will help you understand things a bit better:

http://hotwired.lycos.com/webmonkey/99/ ... rogramming