counter

This is a discussion on counter within the PHP Language forums, part of the PHP Programming Forums category; Hello. I am trying to put one counter in my php with the next code: <?php $hitfile = "/admin/...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-14-2003
[XaToA]
 
Posts: n/a
Default counter


Hello.
I am trying to put one counter in my php with the next code:
<?php

$hitfile = "/admin/contador.txt";
if (!file_exists($hitfile)) {
$file = fopen($hitfile,"r+");
$hits = fread($file,filesize($hitfile));
fclose ($file);
}
else {
$hits = 0;
}
$file = fopen($hitfile,"w+");
fwrite ($file, ++$hits);
fclose ($file);
?>

but when i try to see the php page appears this error:

Warning: fopen(/admin/contador.txt) [function.fopen]: failed to create
stream: No such file or directory in /home/usuairo/pagina.php on line 9

Warning: filesize() [function.filesize]: Stat failed for /admin/contador.txt
(errno=2 - No such file or directory) in /home/usuairo/pagina.php on line 10

Warning: fread(): supplied argument is not a valid stream resource in
/home/usuairo/pagina.php.php on line 10

Warning: fclose(): supplied argument is not a valid stream resource in
/home/usuairo/pagina.php.php on line 11

Warning: fopen(/admin/contador.txt) [function.fopen]: failed to create
stream: No such file or directory in /home/usuairo/pagina.phpcontacto.php on
line 19

Warning: fwrite(): supplied argument is not a valid stream resource in
/home/usuairo/pagina.phpcontacto.php on line 20

Warning: fclose(): supplied argument is not a valid stream resource in
/home/usuairo/pagina.phpcontacto.php on line 21



can you help me for solving the problem and putting one counter in my php
page?
thanks


Reply With Quote
  #2 (permalink)  
Old 08-14-2003
Joshua Ghiloni
 
Posts: n/a
Default Re: counter

Phil Roberts wrote:
> With total disregard for any kind of safety measures "[XaToA]"
> <batarrita_NOSPAM_@excite.com> leapt forth and uttered:
>
>
>>Hello.
>>I am trying to put one counter in my php with the next code:
>><?php
>>
>>$hitfile = "/admin/contador.txt";
>>if (!file_exists($hitfile)) {
>> $file = fopen($hitfile,"r+");
>> $hits = fread($file,filesize($hitfile));
>> fclose ($file);
>>}
>>else {
>> $hits = 0;
>>}
>>$file = fopen($hitfile,"w+");
>>fwrite ($file, ++$hits);
>>fclose ($file);
>>?>
>>
>>but when i try to see the php page appears this error:
>>
>>Warning: fopen(/admin/contador.txt) [function.fopen]: failed to
>>create stream: No such file or directory in
>>/home/usuairo/pagina.php on line 9
>>
>>Warning: filesize() [function.filesize]: Stat failed for
>>/admin/contador.txt (errno=2 - No such file or directory) in
>>/home/usuairo/pagina.php on line 10
>>
>>Warning: fread(): supplied argument is not a valid stream
>>resource in /home/usuairo/pagina.php.php on line 10
>>
>>Warning: fclose(): supplied argument is not a valid stream
>>resource in /home/usuairo/pagina.php.php on line 11
>>
>>Warning: fopen(/admin/contador.txt) [function.fopen]: failed to
>>create stream: No such file or directory in
>>/home/usuairo/pagina.phpcontacto.php on line 19
>>
>>Warning: fwrite(): supplied argument is not a valid stream
>>resource in /home/usuairo/pagina.phpcontacto.php on line 20
>>
>>Warning: fclose(): supplied argument is not a valid stream
>>resource in /home/usuairo/pagina.phpcontacto.php on line 21
>>
>>
>>
>>can you help me for solving the problem and putting one counter
>>in my php page?
>>thanks
>>
>>
>>

>
>
> Use ./admin not /admin. When you prefix a path with / you are
> referencing the root of the filesystem rather than a path relative
> to the script.
>


But what if /admin/contador.txt is valid? The problem I see is one of
backwards logic. If I'm reading this correctly, You should open and read
the file if it doesn't exist. How do you open and read a file that
doesn't exist? Furthermore, if the file does exist, it (as is specified
by later code) contains the number of hits. Why then, if the file
exists, should $hits = 0? I only ask that because that is what this code
is saying.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:38 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0