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 11 of 11
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    counter problems

    http://www.shiver7.com/tutorials/96/

    i used this tutorial to make a php unique ip counter....

    i did everything it said.... but i still get a LONG list of errors....

    please tell me how to fix this..

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Location
    Jackson, Georgia
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might want to show the code you create from the tutorial and then post the errors you get. Otherwise it's like saying " I made a cake and it tastes horrible. I followed the instructions. What did I do wrong?". Info man, info.
    Designer's Toolz; Web & software development community.

    Get your coding questions answered:
    DTZ Forums

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, i was in a rush....

    the list of errors are here.... www.niodesigns.com

    it has a long list oof errors that i dont comprehend...

    the code would be exactly what was on the tutorial above...

    two errors are about phpnews... ignore those....

    scratch the phpnes thing... i fixed that

    but i dunno about the counter,.....
    Last edited by Niosis; 04-11-2004 at 10:19 PM.

  • #4
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    We need to see PHP script, not just the errors it produces.

    If you want a simple counter, look at the first post of http://codingforums.com/showthread.php?t=36476
    Last edited by gsnedders; 04-11-2004 at 10:10 PM.

  • #5
    New Coder
    Join Date
    Mar 2004
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    .... i did exactly what the tut said

    Unique Ip Counter

    So you want a unique ip counter, huh? ok ok i get ya, have a look see you might find something good.

    <?php
    $filename = "hits.txt" ;

    $file = file($filename);
    $file = array_unique($file);
    $hits = count($file);
    echo $hits;

    $fd = fopen ($filename , "r");
    $fstring = fread ($fd , filesize ($filename)) ;
    fclose($fd) ;
    $fd = fopen ($filename , "w");
    $fcounted = $fstring."\n".getenv("REMOTE_ADDR");
    $fout= fwrite ($fd , $fcounted );
    fclose($fd);
    ?>

    I could just explain everything in detail, But im not like that! Now the code above is simple enough as in the filename = "hits.txt"; this basically means it writes the number of unique hits to the file specified. This file MUST be CHMODED to 777 and in the same directory as the php script. Now copy the code above into a blank file and hit "Save As" and save it as counter.php now a new txt file and name it hits.txt save it as an empty txt and upload them together in the same dir and include them back via a PHP include like so

    <?php include('url/to/file/counter.php'); ?>

    You may also put someting infront of it like:

    Total Visitors: <?php include('url/to/file/counter.php'); ?>

    and it will show up like Total Visitors: 3200 I hope this Tutorial has helped u in someway or another.


    this would be the exact directions i followed.... and those are the errors it gives me...

    i copy and pasted that code.... and followed the directions....

    i chmodded every file i was supposed to...

  • #6
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    I think I've found your problem, try moving them to the same folder as where the page you want them to be displayed in.
    Last edited by gsnedders; 04-11-2004 at 10:29 PM.

  • #7
    New Coder
    Join Date
    Mar 2004
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ooo ill try that.... get back to you rreeeeel soon!


    haha! thanks! you da man.... uh.. person!

    yeah you da person....

  • #8
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    I see it worked, and I'm a boy, not man or person, boy, just a boy.

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    That counter is resource wasteful. The while loop is completely useless. A better counter would be:
    PHP Code:
    <?php
    $count_my_page 
    = ("hitcounter.txt");
    $hits file($count_my_page);
    $hits[0] ++;
    $fp fopen($count_my_page "w");
    fputs($fp "$hits[0]");
    fclose($fp);
    echo 
    $hits[0];
    ?>
    Really can't see why the file has to be opened twice.

  • #10
    Regular Coder
    Join Date
    Mar 2004
    Location
    Jackson, Georgia
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mine doesnt need the while loop either...you can use file_get_contents if you have a newer version of PHP (4.2 i believe)

    Code:
    <?php
    $oldcount  =  file_get_contents("count.txt");
    fclose($getcount);
    	$oldcount++;
    $storenew  =  fopen("count.txt",  "w");
    	fputs($storenew,  $oldcount);
    fclose($storenew);
    
    print  $oldcount;
    ?>
    Designer's Toolz; Web & software development community.

    Get your coding questions answered:
    DTZ Forums

  • #11
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by DesignersToolz
    Mine doesnt need the while loop either...you can use file_get_contents if you have a newer version of PHP (4.2 i believe)

    Code:
    <?php
    $oldcount  =  file_get_contents("count.txt");
    fclose($getcount);
    	$oldcount++;
    $storenew  =  fopen("count.txt",  "w");
    	fputs($storenew,  $oldcount);
    fclose($storenew);
    
    print  $oldcount;
    ?>
    Thanks for the new code...


  •  

    Posting Permissions

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