473,412 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

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
Jul 16 '05 #1
1 4534
Phil Roberts wrote:
With total disregard for any kind of safety measures "[XaToA]"
<ba***************@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.

Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shane | last post by:
:) I am following a tutorial for php (hudzilla.org) absolutely loving it however I am having trouble with the counter example <?php // your content here... $filename = 'counter.txt'; // our...
16
by: Paul Rubin | last post by:
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. ...
7
by: JellyON | last post by:
Hi. Is there a way to delay a call to a page counter (ie. call to a server script from an IMG tag) for the purpose to not lock the page loading awaiting counter be displayed. Maybe a...
0
by: Earl Anderson | last post by:
KB Article Q140908 provided the following function to create an Auto Incrementing Counter: Function Next_Custom_Counter () On Error GoTo Next_Custom_Counter_Err Dim MyDB As Database Dim...
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
0
by: Trevor L. | last post by:
I decide to put a custom Hit Counter on my page (below). Then I won't be reliant on the standard FrontPage one which uses webbots. It is called by <b>Hit Counter: </b><!--#include...
12
by: devospice | last post by:
Hi, I'm trying to create a download counter for individual files on a web site and I'm not sure how to do this. Right now I'm using Webalizer to just read the log files and see how many times...
5
by: jasonchan | last post by:
How would you set up a counter in javascript that goes from 5 to 0 This is what i have so far and it is not displaying in the div container "counter" for some reason... <!DOCTYPE html PUBLIC...
3
blackstormdragon
by: blackstormdragon | last post by:
Here were our instructions: "My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to...
2
by: gumbercules | last post by:
I am designing a site that is regulary updated with new podcasts. I would like to be able to have a counter next to each podcast showing how many hits/listens/plays/views each particular podcast has...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.