Skip to main content
gamedev.net
🔒 Locked

Testing post counter script.

Started by griffenjam Aug 4, 2003 at 3:56 PM 5 replies 550+ views
Original Post
griffenjam
griffenjam
Just wrote a post counter in PHP, testing it out.
"There aint gonna be no tea and crumpets!" You are person # to view this post.
griffenjam
griffenjam
It dues use the referer info to create the record for each thread, each thread's post count is shared, but then again, if you view one of my posts in a thread you will have to view them all.
If I really cared I would also add a lookup table of ip addresses that have viewed the thread so I could only record each viewer once, but that is too much like work.

Edit: I'll post the code once I get home, I don't know how to copy more than one line at a time over SSH.

[edited by - griffenjam on August 4, 2003 6:01:49 PM]
griffenjam
griffenjam
Now everyone can tell me how much I suck at PHP




<?php
header("Content-type: image/jpeg");
$im = imagecreate(40, 15);

$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255, 255, 255);


//Connect to database

$ref = $_SERVER[''HTTP_REFERER''];
$query = "SELECT * FROM count WHERE Ref = ''$ref'';";

$username="username";
$password="password";
$database="postcounter";

mysql_connect(localhost, $username, $password);

@mysql_select_db($database) or die("Unable to open database");

$result = mysql_query($query);
$num=mysql_numrows($result);
$viewcount = 0;

if($num == 0)
{
//Create a new row

$query = "INSERT INTO count VALUES(''$ref'', 1);";
$result = mysql_query($query);
}
else
{
//Get the current count

$viewcount = mysql_result($result, 0, "count");
//increment count

$viewcount = $viewcount + 1;
$query = "UPDATE count SET count = $viewcount;";
$result = mysql_query($query);
}
ImageString($im, 3, 0, 0, $viewcount, $white);

Imagejpeg($im);
ImageDestroy($im);

mysql_close();
?>





"There aint gonna be no tea and crumpets!"
You are person # to view this post.
Mscgamer
Mscgamer
I stole your "post counter" to use on another site. KTHXBYE!
griffenjam
griffenjam
I don''t care, but there is something wrong it it. It you got to a page with one of your posts in it, then it your back button and make a post it seems that it somehow keeps the postcount value and applies it to the new thread. ohh well.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.