Bjames
07-18-2003, 09:51 PM
Can someone give me the codeing for a counter to keep track of how many people have visited my site?
Thanks!!!!
Thanks!!!!
|
Click to See Complete Forum and Search --> : Site page counter Bjames 07-18-2003, 09:51 PM Can someone give me the codeing for a counter to keep track of how many people have visited my site? Thanks!!!! AdamBrill 07-18-2003, 09:54 PM You need to use server-side code to do that. You could try either PHP, ASP, CGI, etc. If you want PHP, I can give you some code... AdamBrill 07-18-2003, 09:59 PM Here is the PHP code:<?PHP $file = "counter.txt"; #chmod to 666 $contents = @file($file); #open the file for reading $count = $contents[0]; #put the first line of $contents into $count $count++; #increment $count by 1 $fp = fopen($file, "w"); #open the file for writing. echo $count; fwrite ($fp, $count); #write count to the file fclose ($fp); #close the file ?>Just create a file called counter.txt and put a 0 in it. Then put it in the same directory as the page you want to be counted. Credit for this code goes to Pyro. ;) rpanning 07-18-2003, 10:00 PM AdamBrill's code will work but if you want a few to choose from go to http://www.hotscripts.com/PHP/Scripts_and_Programs/Counters/index.html Just a FYI. pyro 07-18-2003, 10:26 PM And the only other (or rather one of the things... :p) thing I should have done the first time around is flock'ed the file... <?PHP $file = "counter.txt"; #chmod to 666 $contents = @file($file); #open the file for reading $count = $contents[0]; #put the first line of $contents into $count $count++; #increment $count by 1 $fp = fopen($file, "w"); #open the file for writing. flock ($fp, 2); #lock the file echo $count; fwrite ($fp, $count); #write count to the file flock($fp, 3); #release the file fclose ($fp); #close the file ?>Note that flock only works on *nix file systems... Tamango 07-28-2003, 02:23 PM This might seem like a STUPID question, but please cope with me :D . Where would I paste the PHP code?? In the index.htm file, or make a counter.php file?? pyro 07-28-2003, 02:27 PM That particuar code would go on the page that you want to count. Also, don't forget to make a counter.txt file, and CHMOD it to 666. And, PHP will generally only works in files with a .php extention... Tamango 07-28-2003, 02:40 PM If im pasting the PHP code in the htm page I want to monitor page hits, why did you say I will need a .php extention?? It's pasted in the body of the htm or head? pyro 07-28-2003, 02:48 PM You need to use a .php extention because you are using PHP. That tells the server that it needs to run the page through the PHP parser. You paste the code wherever you want the counter to show up on your page. sciguyryan 08-02-2003, 10:32 AM hi all, here's my one <TABLE BORDER=4><TR><TD> <APPLET CODEBASE="http://www7.counter.bloke.com/c/" CODE="Counter.class" WIDTH=75 HEIGHT=20> <PARAM NAME=URL VALUE="your web adress here"> <PARAM NAME=reset VALUE="0"> <PARAM NAME=img VALUE="/c/default-black-red.gif"> </APPLET></TD></TR></TABLE> just ann your web adress to the [COLOR=red] red [/COLOR=red] part. ChangedSoul 02-04-2004, 02:33 AM Ok, Im a bit studpid with this PHP stuff. today it the first ive heard of it. I cut that code out and put it in my page, created a .txt file with the number 0 in it and saved it as counter.txt, now what this about "CHMOD it to 666". whas that all about? How do I go about doing this? Thanks. Pittimann 02-04-2004, 02:47 AM Hi! Please check this out to learn a bit about chmod: http://de2.php.net/manual/en/function.chmod.php To use PHP, your server needs to support it! I guess, you just saved your textfile locally. But your machine at home might not be a server and (concerning this, I'm quite sure) you don't have PHP installed at home. Please check, whether your server supports PHP. If so, upload your textfile to the server. To change the mode (chmod) you can use almost every ftp program instead of doing it by running the PHP command... Cheers - Pit webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |