rusty.nells
New Member
- Reaction score
- 0
- Location
- Republic Of Texas
Here it is, the actual hit counter ->
First of all, I should warn you:
I am not an expert PHP coder. I can't guarantee the worthiness of this script. If you get a twitter worm or attract the attention of any government agencies, it's not my fault
Anyone can do whatever you like with this script. Post it on a blog, post it on sourceforge, sell it on ebay etc. You are not bound by any license, this is absolutely free for personal or commercial use. You don't even have to credit me. However, if you're feeling generous, you can credit "copyright1968" (my usual online nickname).
It's just a simple script, nothing fancy, no cool features. It counts all page views, not unique page views. If you were to view a page with this counter and refresh the page 10 times, the count will be incremented by 10.
There's no need to enter items into the database, they are automatically added via the query string (eg. ?item=WHATEVER). Once you create the database, you never have to bother with it again. Unless you want to remove items, and you likely will.
This requires PHP with GD and MySQL. For MySQL you'll need a database, database host, user name and password, all are usually provided by your host. If you run your own server, you'll already know these.
Just copy and save the following code as viewer.php (or any name). Edit the $db, $dbhost, $dbuser and $dbpassword fields with your info.
Next, create the table clcounter in your database. You'll need two fields for item and viewcount. You can create it manually or use the following SQL code
Now (assuming you uploaded to the root directory) insert the following code in to your craigslist post. Edit MYWEBSITE.COM and YOUR_ITEM_NAME. If item=showall, it will list all items and their page views.
I uploaded this to http://technibblerocks.atbhost.net/viewer.php?item=showall (a free host). If you don't have a web site, you can use this one:
each item name should be unique to display the page views for that specific item. If not, multiple counters will display the same number for multiple posts with the same item name.
First of all, I should warn you:
I am not an expert PHP coder. I can't guarantee the worthiness of this script. If you get a twitter worm or attract the attention of any government agencies, it's not my fault

Anyone can do whatever you like with this script. Post it on a blog, post it on sourceforge, sell it on ebay etc. You are not bound by any license, this is absolutely free for personal or commercial use. You don't even have to credit me. However, if you're feeling generous, you can credit "copyright1968" (my usual online nickname).
It's just a simple script, nothing fancy, no cool features. It counts all page views, not unique page views. If you were to view a page with this counter and refresh the page 10 times, the count will be incremented by 10.
There's no need to enter items into the database, they are automatically added via the query string (eg. ?item=WHATEVER). Once you create the database, you never have to bother with it again. Unless you want to remove items, and you likely will.
This requires PHP with GD and MySQL. For MySQL you'll need a database, database host, user name and password, all are usually provided by your host. If you run your own server, you'll already know these.
Just copy and save the following code as viewer.php (or any name). Edit the $db, $dbhost, $dbuser and $dbpassword fields with your info.
PHP:
<?php
$db = "";
$dbhost = "";
$dbuser = "";
$dbpassword = "";
if(isset($_GET['item']))
{
if ($_GET['item'] == "showall"){
mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error()) ;
mysql_select_db($db) or die(mysql_error()) ;
$result = mysql_query("SELECT * FROM clcounter") ;
echo "<table border=1 width=400><tr><td width=200><b>Item</b></td><td width=200><b>Count</b></td></tr>";
while($row=mysql_fetch_array($result)){
echo "<tr><td>$row[item]</td><td>$row[viewcount]</td></tr>";
}
echo "</table>";
exit();
}
$item = addslashes($_GET['item']);
mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error()) ;
mysql_select_db($db) or die(mysql_error()) ;
$result = mysql_query("SELECT viewcount FROM clcounter WHERE item = '$item'") ;
$check = mysql_num_rows($result);
if ($check == 0) {
mysql_query("INSERT INTO clcounter (item, viewcount) VALUES ('$item', '0')") ;
}
$result = mysql_query("SELECT viewcount FROM clcounter WHERE item = '$item'") ;
while($row = mysql_fetch_array($result)){
$viewcount = $row['viewcount'];
$viewcount++;
mysql_query("UPDATE clcounter SET viewcount='$viewcount' WHERE item = '$item'") ;
}
$pagecounter = imagecreate(60, 20);
$background = imagecolorallocate($pagecounter, 255, 153, 0);
$textcolor = imagecolorallocate($pagecounter, 0, 0, 0);
imagestring($pagecounter, 5, 4, 4, $viewcount, $textcolor);
header("Content-type: image/png");
imagepng($pagecounter);
imagecolordeallocate($textcolor);
imagecolordeallocate($background);
imagedestroy($pagecounter);
}else{
header("Location: index.php");
}
?>
Next, create the table clcounter in your database. You'll need two fields for item and viewcount. You can create it manually or use the following SQL code
Code:
CREATE TABLE `clcounter` (
`item` tinytext collate latin1_general_cs NOT NULL,
`viewcount` smallint(7) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
Now (assuming you uploaded to the root directory) insert the following code in to your craigslist post. Edit MYWEBSITE.COM and YOUR_ITEM_NAME. If item=showall, it will list all items and their page views.
HTML:
<img src=http://MYWEBSITE.COM/viewer.php?item=YOUR_ITEM_NAME width=60 height=20 border=1>
I uploaded this to http://technibblerocks.atbhost.net/viewer.php?item=showall (a free host). If you don't have a web site, you can use this one:
HTML:
<img src=http://technibblerocks.atbhost.net/viewer.php?item=YOUR_ITEM_NAME width=60 height=20 border=1>
each item name should be unique to display the page views for that specific item. If not, multiple counters will display the same number for multiple posts with the same item name.