Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can't get counter code working !!!

    Hi there,

    I'm very green again, three years ago I loved working with PhP and now the same as before I have to ask questions.
    I just started a new web site again and wanted to use my so beloved PhP code. I can view web pages with php code but if I want to use code for a hit counter I get errors !!! I have used this code snippets hundrets of times but this time no luck.
    My question is here really is if anybody could tell me if it is these days enough to just have the php code as below OR do I have to include anything else in a wepage ( I always had to use the following on the very top in my old .php pages)
    PHP Code:
    #!/usr/local/bin/php 
    I useed this code for the counter"
    PHP Code:
    <?php
    $counter 
    "counter_intro.txt";
    function 
    displayCounter($counter)
        {
            
    $fp fopen("$counter""r");
            
    $num fread$fp100);
            
    $fpsoma = ($num 1);
            
    fclose($fp);
            
    $fa fopen("$counter""w");
            
    fwrite$fa$fpsoma100);
            
    fclose($fa);
            echo 
    "<font color=#00ff00><center>$fpsoma</center></font>";
        }
    displayCounter($counter);
    ?>
    Thanks in advance for any help. aktell

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    Your first - #!/usr/local/bin/php - is unnecessary.

    Your code works for me. If the .txt file does not initially exist, there would be an warning error output on the first fopen, but the file would be created by the second fopen. The code would then work thereafter.

    If it is not working for you there is likely a permissions problem that is preventing PHP from performing the file functions. Add the following after your opening <?php tag to see what might be occurring -
    PHP Code:
    error_reporting(E_ALL); 
    Last edited by CFMaBiSmAd; 11-03-2006 at 03:50 AM. Reason: fixed a word
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Hi there,

    It's a while but only today I was able to return to this problem. It is still not working I have taken your advise and includet your code but it did not make a difference.
    I have this site address to view for anybody to see what is reporting ???.

    Thanks aktell
    Last edited by aktell; 11-10-2006 at 01:38 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •