We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
View Counter
Topic Started: Aug 14 2005, 06:27 PM (728 Views)
Auron89
Member
[ *  *  *  *  *  *  * ]
I'm having trouble finding a decent script which counts the amount of hits a certain link/image link recieves. Can anyone help? (I'm sure it's done through PHP - I may be wrong!) :)
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
Well, you would have to make the page/image actually a PHP script.

For example (for images), instead of "http://www.domain.com/image.gif", you would make a PHP script called "http://www.domain.com/image.php?img=image.gif". In image.php, you would do this:

Code:
 
<?php
$hits=0;
if (file_exists("imagehits".$img.".txt")) { $hits=file_get_contents("imagehits".$img.".txt"); }
$hits++;
$f=fopen("imagehits".$img.".txt","w");
fwrite($f,$hits);
fclose($f);
$img=imagecreatefromgif($img);
header("Content-type: image/png");
imagepng($img);
?>


Then on your server, there will be created files called "imagehits*.php", where the * is replaced by the image filename. Inside those files will be h=the number of hits it got.

Instead of an image, if you want a link, then rename that page with a .php extension and add this at the end:

Code:
 
<?php
$hits=0;
if (file_exists("pagehits".$_SERVER['SCRIPT_NAME'].".txt")) { $hits=file_get_contents("hits".$img.".txt"); }
$hits++;
$f=fopen("imagehits".$img.".txt","w");
fwrite($f,$hits);
fclose($f);
?>


This will give the same outcome as the image one, except the filenames will be "hits*.txt" where the * is replaced by the filename of the page.

-IMP ;) :)
Offline Profile Quote Post Goto Top
 
Auron89
Member
[ *  *  *  *  *  *  * ]
Right, thanks very much. I'll try that. :)
Offline Profile Quote Post Goto Top
 
mobashirkhan
Member
[ * ]
how and where can i put that code and tell me where can i edit my picture???
Offline Profile Quote Post Goto Top
 
Veris
Member Avatar
Kaput!
[ *  *  * ]
Yea, but when using the php script, instead of changing all your images, cant you just change it from index.html to index.php.
Offline Profile Quote Post Goto Top
 
mobashirkhan
Member
[ * ]
i still can't understand that what r u trying to say???
tell me in detail plz
Offline Profile Quote Post Goto Top
 
Auron89
Member
[ *  *  *  *  *  *  * ]
Maybe you should make your own topic? This one is kinda old.
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
Yesh, it is, but...

@mobashirkhan: You need to put it in a file with a .php extension and host it on a server that allows PHP (Ripway is a good one).

@Illuminatie: No.... I think you are a little confused. The index.php or index.html file is independant from the images. While they may include images, the images are loaded from separate files, hence the need for the SRC property of the <img> HTML tag. By making the SRC a single PHP file and just changing the filename after the ?img= in the URL to the PHP file, you do not need to change any images, but rather you only need to change the SRC in the <IMG> tags.

-IMP ;) :)
Offline Profile Quote Post Goto Top
 
mobashirkhan
Member
[ * ]
oohhh :) thanx
brother
Offline Profile Quote Post Goto Top
 
Veris
Member Avatar
Kaput!
[ *  *  * ]
Alright, i've seen different ways to do it.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply