Web hit counter program with PHP
Dear my friends... I am writing a program to count how many time my homepage has been visited with PHP. The algorithm is: " if the visitor doesn't have the cookies, that means he/she just visited my homepage after the last time he/she close his/her internet browser. So I open my file which located in the directory of my homepage to read and increased the value inside it once. " I am using SuSE Linux 8.1 and PHP 4.2.2. But I'm stucked with these error message: " Warning: fopen("ngitung.txt", "w") - Permission denied in /srv/www/htdocs/iamsoft/isimuka.php on line 9 Warning: fwrite(): supplied argument is not a valid File-Handle resource in /srv/www/htdocs/iamsoft/isimuka.php on line 10 Warning: fclose(): supplied argument is not a valid File-Handle resource in /srv/www/htdocs/iamsoft/isimuka.php on line 11 Warning: fopen("ngitung.txt", "r") - No such file or directory in /srv/www/htdocs/iamsoft/isimuka.php on line 13 Warning: fread(): supplied argument is not a valid File-Handle resource in /srv/www/htdocs/iamsoft/isimuka.php on line 14 Warning: fclose(): supplied argument is not a valid File-Handle resource in /srv/www/htdocs/iamsoft/isimuka.php on line 16 Warning: fopen("ngitung.txt", "w") - Permission denied in /srv/www/htdocs/iamsoft/isimuka.php on line 18 Warning: fwrite(): supplied argument is not a valid File-Handle resource in /srv/www/htdocs/iamsoft/isimuka.php on line 19 Warning: fclose(): supplied argument is not a valid File-Handle resource " Any body would be so nice to help me? Please tell me what should I do. Here is my code: " <HTML> <BODY bgcolor="white"><FONT type="arial" size="3"><CENTER><IMG SRC="gambar/LogoI@m.jpg" border="0"></CENTER> <BR><BR><BR> <?PHP if (!isset($tamunyaiamsoft)){ $berkastamu = "ngitung.txt"; if (!file_exists($berkastamu)){ $bukafile = fopen($berkastamu, "w"); fwrite($bukafile, "1"); fclose($bukafile); } $bukafile = fopen($berkastamu, "r"); $urut = fread($bukafile, 5); echo $urut; fclose($bukafile); $urut++; $bukafile = fopen($berkastamu, "w"); fwrite($bukafile, $urut); fclose($bukafile); if (!isset($OK)){ header("Location: $PHP_SELF"."?OK=1"); exit; } } ?> <CENTER><IMG SRC="gambar/banner.gif" border="0"></CENTER> <CENTER><H1>Under construction for "i@m"</H1></CENTER> <CENTER> <B> <?PHP if (isset($tamunyaiamsoft)){ echo "$tamunyaiamsoft.visitors since March 24, 2003.\n"; } ?> </B> </CENTER> <CENTER><I><FONT type="arial" size="2.9" color="blue"> <B>Best viewed with : Mozilla and Konqueror Browsers. Resolutions : 1024 x 728.<BR> Please enable cookies, JavaScript and JavaApplet on your browser.</B> </FONT></I></CENTER><BR><BR><BR> </FONT></BODY> </HTML> " Thank you very much in advance. __________________________________________________ Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! http://platinum.yahoo.com
Dear my friends...
I am writing a program to count how many time my homepage has been visited with PHP. The algorithm is: " if the visitor doesn't have the cookies, that means he/she just visited my homepage after the last time he/she close his/her internet browser. So I open my file which located in the directory of my homepage to read and increased the value inside it once. "
I am using SuSE Linux 8.1 and PHP 4.2.2.
But I'm stucked with these error message: " Warning: fopen("ngitung.txt", "w") - Permission denied in /srv/www/htdocs/iamsoft/isimuka.php on line 9 This appears to be the root of all your problems. You web server does not have write priviledge in the current directory, so ngitung.txt does not get written on the server. I might suggest you either make the
On Mon, 24 Mar 2003 03:34:52 -0800 (PST) Prabu Subroto <prabu_subroto@yahoo.com> wrote: directory writable, or (better) put ngitung.txt in another directory that is writable. You could set up a symlink to that directory so that so you don't have to change your code. (eg. set up the symlink to /tmp/ngitung.txt). -- -- Gerald Feldman <gfeldman@attbi.com> Boston Computer Solutions and Consulting ICQ#156300 PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Dear Jerry... Firstly, thank you for your help. There are some things that I have not understood. 1. If I want to make my web server (Apache) may write into "/srv/www/htdocs/iamsoft/ngitung.txt", how should I do that? 2. If I want to make a writable directory, how should I do that? 3. If I can also use symlink, how should I do that? Is it somewhat like "ln -s"? I am looking forward to your further explanation, thank you very much in advance.... --- Jerry Feldman <gfeldman@attbi.com> wrote:
On Mon, 24 Mar 2003 03:34:52 -0800 (PST) Prabu Subroto <prabu_subroto@yahoo.com> wrote:
Dear my friends...
I am writing a program to count how many time my homepage has been visited with PHP. The algorithm is: " if the visitor doesn't have the cookies, that means he/she just visited my homepage after the last time he/she close his/her internet browser. So I open my file which located in the directory of my homepage to read and increased the value inside it once. "
I am using SuSE Linux 8.1 and PHP 4.2.2.
But I'm stucked with these error message: " Warning: fopen("ngitung.txt", "w") - Permission denied in /srv/www/htdocs/iamsoft/isimuka.php on line 9 This appears to be the root of all your problems. You web server does not have write priviledge in the current directory, so ngitung.txt does not get written on the server. I might suggest you either make the directory writable, or (better) put ngitung.txt in another directory that is writable. You could set up a symlink to that directory so that so you don't have to change your code. (eg. set up the symlink to /tmp/ngitung.txt).
-- -- Gerald Feldman <gfeldman@attbi.com> Boston Computer Solutions and Consulting ICQ#156300 PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists/archive/suse-programming-e
__________________________________________________ Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! http://platinum.yahoo.com
On Mon, 24 Mar 2003 04:24:24 -0800 (PST) Prabu Subroto <prabu_subroto@yahoo.com> wrote:
Dear Jerry...
Firstly, thank you for your help.
There are some things that I have not understood.
1. If I want to make my web server (Apache) may write into "/srv/www/htdocs/iamsoft/ngitung.txt", how should I do that? Make the iamsoft directory writable. But be very careful since by making it writable you open it up to a multitude of security risks.
2. If I want to make a writable directory, how should I do that? use the chmod command (eg. chmod o+w directory). I'm not going to go into the details. I suggest that you do not make your main document directories writable for security issues, which is why I suggested a symlink.
3. If I can also use symlink, how should I do that? Is it somewhat like "ln -s"? ln -s /tmp/ngitung.txt /srv/www/htdocs/iamsoft/ You need to have permission in /srv/www/htdocs/iamsoft/ to set the link (eg. become root).
Note that Apache should be running as the "nobody" user.
participants (2)
-
Jerry Feldman
-
Prabu Subroto