Reply to Re: Count the visitor of website

Your name:

Reply:


Posted by Jerry Stuckle on 09/29/07 03:00

Dev wrote:
> Dear All,
> i have get combination of four PHP script for count the visitor of
> website but when i apply all these i have no answer.
> i am posting the code of all four PHP script below.
>
> CODE OF INDEX.PHP
> <?php
>
> print "<font face='verdana' size='1'>";
>
> If (file_exists( "counter.txt" )){
> include_once "read.php";
>
> $count++;
>
> echo "This page has been visited <b>$count</b> times";
>
> include_once "write.php";
> } else {
> print "<font color='red'><b>Error</b>: Cannot find Counter Data File!
> </font>";
> }
>
> print "</font>";
>
> ?>
>
>
> CODE OF COUNT.PHP
> <?php
>
> print "<font face='verdana' size='1'>";
>
> If (file_exists( "counter.txt" )){
> include_once "read.php";
>
> $count++;
>
> include_once "write.php";
> } else {
> print "<font color='red'><b>Error</b>: Cannot find Counter Data File!
> </font>";
> }
>
> print "</font>";
>
> ?>
>
> CODE OF READ.PHP
> <?php
> $file = "counter.txt";
>
> $open = fopen( $file, "r" );
> $count = fread ( $open, filesize ( $file ) );
> fclose( $open );
> ?>
>
> CODE OF WRITE.PHP
> <?php
> $file = "counter.txt";
>
> $open = fopen( $file, "w" );
> fwrite( $open, $count );
> fclose( $open );
> ?>
>
> THERE IS ONE FILE ALSO NAMED COUNTER.TXT HAVING 0
>
> any body help me to apply these correctly because i am new to PHP.
> Please tell me
> 1. correct location of each script in my index.html page
> 2. any extra code (if any) for the index.html page.
>
> thanks in advance.
>
> Dev
>

First of all, enable all errors and display them (see your php.ini
file). You will see your error.

You need to have something in your file before you can read it. Just
initialize it to 0 (numeric zero) with your favorite editor and it
should be ok.

Also, ensure the webserver userid has read/write access to the file.

And you have another potential problem which will show up sooner or
later - two different people accessing the file at the same time. You
may just lose one update - or you could screw up the file altogether.
You really need to lock the file from before you open it for reading
until after you close it for writing.

As for where to put it? Something like this can go anywhere between the
<body> and </body> tags - depends on where you want to display it.

But also, just forget it. A counter on a page is a sure sign of a
newbie (or someone who needs their ego stroked :-) ). Rather. use the
logs to get the information.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация