All right, well in class, I have to make a counter that I'll be able to display on my student profile.
I need to have an image display every time a specific URL is visited. On that image it shows how many times that URL has been visited.
Lol, I'll give you an example.
[My profile has had 12 visits]
and if you visit myprofileorw/e.com the image will be
[My profile has had 13 visits]
I almost got the code working.
My index class:
counter.phpCode:<?php
//Send a generated image to the browser
create_image();
exit();
function create_image()
{
include ("counter.php");
//Let's generate a totally random string using md5
$md5 = md5(rand(0,999));
//We don't need a 32 character long string so we trim it down to 5
$number = "5";
$counter = $number + 1;
$pass = "I have $hits[0] views...";
//Set the image width and height
$width = 350;
$height = 20;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
//Make the background black
ImageFill($image, 0, 0, $black);
//Add randomly generated string in white to the image
ImageString($image, 3, 2, 3, $pass, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image,0,0,$width-1,$height-1,$grey);
//imageline($image, 0, $height/2, $width, $height/2, $grey);
//imageline($image, $width/2, 0, $width/2, $height, $grey);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
?>
counter.txtCode:<?php
$count_my_page = ("counter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
?>
So the code works and all, except when I doCode:12
but the counter goes up every time someone goes on a page where my img is displayed, it's only supposed to go up when you visit myprofileorw/e.comQuote:
I put [*img]www.yadaydayday.com/index.php[*/img] the image is displayed
Thanks.
