Neoseeker : Blogs : Benedict

Benneh's blog

PHP count number of times link has been clicked

    This script is for Monferno, as he requested it, but I thought I would share it with other people so the google crawlbots can get at it.


    To use this, create two pages and one file: The php page with the link on, (I use count.php) and the php page that is linked to (I use count2.php), and a blank text file in the same directory (I use 1.txt).

    First, in the page that is being linked to (count2.php) put this code at the top of the body:
    code
    <?php
    error_reporting(0); #Removes Notices that appear with this code
    $count_my_page = ("1.txt");
    $hits = file($count_my_page);
    $hits[0] ++;
    $fp = fopen($count_my_page , "w");
    fputs($fp , "$hits[0]");
    fclose($fp);
    ?>
    


    That will write one number onto the file (1.txt) which can be echoed later on the other page.

    Now, on your page with the links put this in the head (Count.php):
    code
    <script language="javascript">
    function toggle() {
    var linkname = 

read more..
(0.2029/d/aeon)