...

View Full Version : counter problems



Niosis
04-11-2004, 07:17 PM
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..

DesignersToolz
04-11-2004, 07:20 PM
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.

Niosis
04-11-2004, 10:03 PM
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 :thumbsup:

but i dunno about the counter,..... :confused: :(

gsnedders
04-11-2004, 10:07 PM
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

Niosis
04-11-2004, 10:21 PM
.... 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...

gsnedders
04-11-2004, 10:26 PM
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.

Niosis
04-11-2004, 10:31 PM
ooo ill try that.... get back to you rreeeeel soon!


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

yeah you da person....

gsnedders
04-11-2004, 10:39 PM
I see it worked, and I'm a boy, not man or person, boy, just a boy.

Nightfire
04-12-2004, 12:04 AM
That counter is resource wasteful. The while loop is completely useless. A better counter would be:


<?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.

DesignersToolz
04-12-2004, 02:27 AM
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)



<?php
$oldcount = file_get_contents("count.txt");
fclose($getcount);
$oldcount++;
$storenew = fopen("count.txt", "w");
fputs($storenew, $oldcount);
fclose($storenew);

print $oldcount;
?>

gsnedders
04-12-2004, 11:17 AM
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)



<?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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum