Using PHP to count hits on a link
Posted: Wed Mar 25, 2009 2:05 pm
Hi
Firstly, I'd just like to mention that I am almost entirely new to PHP. I have two PHP pages, and I intend to have the following effect:
Any person can go to this website, and it gives them a link. Then, when others click on this link it records their hit onto a flat text database, which is then accessed by the first person's PHP, and, if there are enough hits on his/her link, prints an image.
I've been trawling the web (and am using things learnt from this trawling), and would appreciate it greatly if someone could
Okay, so there are two PHP pages:
home.php
And my other php file, pics.php
(most of this is copied from a tutorial, and so I'm not sure about it.
Sorry if this is simple PHP and I'm entirely missing something. Any help would be received with gratitude, as I am entirely stumped on this. 
Thanks,
Martin
EDIT: And one other thing, will the hit counter make a .txt file? If not, how could I go about doing this? Or would I have to make lots of blank .txt files? Thanks
Firstly, I'd just like to mention that I am almost entirely new to PHP. I have two PHP pages, and I intend to have the following effect:
Any person can go to this website, and it gives them a link. Then, when others click on this link it records their hit onto a flat text database, which is then accessed by the first person's PHP, and, if there are enough hits on his/her link, prints an image.
I've been trawling the web (and am using things learnt from this trawling), and would appreciate it greatly if someone could
Okay, so there are two PHP pages:
home.php
Code: Select all
<?php
$link = "rand (0, 99999999)"; // crude, but I hope it would work
setcookie(linkid, "$link", time()+11197440000);
$getmore="To get more pictures, send the link below to lots of people";
$print "$getmore";
$fulllink="www.exceptional.pcriot.com/pics.php?identity="$_COOKIE["linkid"]";
$print "$fulllink";
// Can I do something better with this? A direct print or echo would be easiest, right?
if $_COOKIE["linkid"].txt >= 0, print("<img src=http://imgupload.com/pic1.jpg>"); else print("<img src=lock.jpg>");
if $_COOKIE["linkid"].txt >= 1, print("<img src=http://imgupload.com/pic2.jpg>"); else print("<img src=lock.jpg>");
// the URL's are just an example
?>
(most of this is copied from a tutorial, and so I'm not sure about it.
Code: Select all
<?php
?$count_my_page = ("$_REQUEST['identity'].txt");?
$hits = file($count_my_page);?
$hits[0] ++;?
$fp = fopen($count_my_page , "w");?
fputs($fp , "$hits[0]");?
fclose($fp);?
?>
Thanks,
Martin
EDIT: And one other thing, will the hit counter make a .txt file? If not, how could I go about doing this? Or would I have to make lots of blank .txt files? Thanks