TexasMd91
06-03-2007, 02:45 AM
In this tutorial I will teach you how to make this.
http://dynamicsig.100webspace.net/visitorsig.jpg/
To start off create a new folder with ".jpg" at the end (to trick browsers to think its an image), I will be using visitorsig.jpg
Here is going to be the file structure
(bold is a folder, non-bold is a file)
visitorsig.jpg
--index.php
--background.jpg
--sigcounter.txt
--fonts
----arial.ttf
Now inside that folder create an "Index.php" This will be where all the code is kept.
This is what Index.php will look like
<?php
Header ('Content-type: image/jpeg');
//START OF COUNTING
$counter = "sigcounter.txt";
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$current_date = $mday . $month . $year;
$fp = fopen($counter, "a");
$line = $REMOTE_ADDR . "|" . $mday . $month . $year . "\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);
$contents = file($counter);
$total_hits = sizeof($contents);
$total_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
array_push($total_hosts, $entry[0]);
}
$total_hosts_size = sizeof(array_unique($total_hosts));
// Daily hits;
$daily_hits = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hits, $entry[0]);
}
}
$daily_hits_size = sizeof($daily_hits);
$daily_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hosts, $entry[0]);
}
}
$daily_hosts_size = sizeof(array_unique($daily_hosts));
//START OF IMAGE
$img_width = 300;
$img_height = 92;
$image = imagecreatefromjpeg("background.jpg");
$white = imagecolorallocate($image, 255, 255, 255);
$font = './fonts/arial.ttf';
ImageTTFText ($image, 8, 0, 10, 20, $white, $font, "Image Hits: ".$total_hits);
ImageTTFText ($image, 8, 0, 10, 40, $white, $font, "Unique hits: ".$total_hosts_size);
ImageTTFText ($image, 8, 0, 10, 60, $white, $font, "Todays Image hits: ".$daily_hits_size);
ImageTTFText ($image, 8, 0, 10, 80, $white, $font, "Todays unique hits: ".$daily_hosts_size);
imagepng($image);
imagedestroy($image);
?>
Be sure to not leave any spaces before <?php or after ?>, it will cause an error.
Now create a background.jpg, it needs to be 300x92
I will be using this background.
http://img228.imageshack.us/img228/2143/backgroundzb8.jpg
http://img228.imageshack.us/img228/2143/backgroundzb8.jpg
The sigcounter.txt will be created when the image is first looked at.
Now create a fonts folder under your .jpg folder and inside upload arial.ttf, this can be found in c:/windows/fonts/arial.tff
Now just go to http://YOUR DOMAIN NAME HERE/visitorsig.jpg!
http://dynamicsig.100webspace.net/visitorsig.jpg/
To start off create a new folder with ".jpg" at the end (to trick browsers to think its an image), I will be using visitorsig.jpg
Here is going to be the file structure
(bold is a folder, non-bold is a file)
visitorsig.jpg
--index.php
--background.jpg
--sigcounter.txt
--fonts
----arial.ttf
Now inside that folder create an "Index.php" This will be where all the code is kept.
This is what Index.php will look like
<?php
Header ('Content-type: image/jpeg');
//START OF COUNTING
$counter = "sigcounter.txt";
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$current_date = $mday . $month . $year;
$fp = fopen($counter, "a");
$line = $REMOTE_ADDR . "|" . $mday . $month . $year . "\n";
$size = strlen($line);
fputs($fp, $line, $size);
fclose($fp);
$contents = file($counter);
$total_hits = sizeof($contents);
$total_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
array_push($total_hosts, $entry[0]);
}
$total_hosts_size = sizeof(array_unique($total_hosts));
// Daily hits;
$daily_hits = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hits, $entry[0]);
}
}
$daily_hits_size = sizeof($daily_hits);
$daily_hosts = array();
for ($i=0;$i<sizeof($contents);$i++) {
$entry = explode("|", $contents[$i]);
if ($current_date == chop($entry[1])) {
array_push($daily_hosts, $entry[0]);
}
}
$daily_hosts_size = sizeof(array_unique($daily_hosts));
//START OF IMAGE
$img_width = 300;
$img_height = 92;
$image = imagecreatefromjpeg("background.jpg");
$white = imagecolorallocate($image, 255, 255, 255);
$font = './fonts/arial.ttf';
ImageTTFText ($image, 8, 0, 10, 20, $white, $font, "Image Hits: ".$total_hits);
ImageTTFText ($image, 8, 0, 10, 40, $white, $font, "Unique hits: ".$total_hosts_size);
ImageTTFText ($image, 8, 0, 10, 60, $white, $font, "Todays Image hits: ".$daily_hits_size);
ImageTTFText ($image, 8, 0, 10, 80, $white, $font, "Todays unique hits: ".$daily_hosts_size);
imagepng($image);
imagedestroy($image);
?>
Be sure to not leave any spaces before <?php or after ?>, it will cause an error.
Now create a background.jpg, it needs to be 300x92
I will be using this background.
http://img228.imageshack.us/img228/2143/backgroundzb8.jpg
http://img228.imageshack.us/img228/2143/backgroundzb8.jpg
The sigcounter.txt will be created when the image is first looked at.
Now create a fonts folder under your .jpg folder and inside upload arial.ttf, this can be found in c:/windows/fonts/arial.tff
Now just go to http://YOUR DOMAIN NAME HERE/visitorsig.jpg!