 |
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5  | This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 14th, 2003, 12:38 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hit_counter1.php problems
Hi
I am currently trying the Try It Out on page 328 (Ch10) and have used the files downloaded from Wrox.com however, when reloading the page as suggested on page 329 the counter does not increment, has anyone else had the same problem as I cannot work out why this may not be working.
One thing is that I had to create the file count.dat as there wasn't one amongst the code download, am I supposed to populate this file with anything? I assume that I don't as the code suggests that it will write to this file each time the page is reloaded.
Any help would be most appreciated.
Thanks in advance
Jamal
|
|

October 14th, 2003, 02:24 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
Hi Jamal,
We actually just addressed this issue in another thread (maybe a few days old!).
Here is the complete solution. Which was written in Italian, but you should have no problem deciphering what is what! The problem ended up relating to the IE cache process, and verifying write permissions.
The thread:
http://p2p.wrox.com/topic.asp?TOPIC_ID=5140
The complete code:
I used an absolute path in my test of the script, but you can throw in a relative path if it serves you to do so.
Code:
<?php
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0[/blue]
# open cacchio.dat for read only
$fp = fopen("G:\\www\\cacchio.dat", "r");
# if $fp is an empty value, issue file read error
if (!$fp) {echo "il file non esiste";}
# read cacchio.dat up to the first 20 bytes or end of file
$contatore = (int) fread($fp, 20);
# close the file and purge it from memory
fclose($fp);
#increment the counter
$contatore++;
echo $contatore;
# reopen and truncate cacchio.dat for writing, if cacchio.dat does not exist, create it
$fp = fopen("G:\\www\\cacchio.dat", "w");
# write the incremented value to the file
fwrite($fp, $contatore);
fclose($fp);
?>
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
|
|

October 14th, 2003, 02:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I feel it's worth mentioning that over 90% of the time this is reported, the problem lies with your file/directory permissions, not with cache control.
Take care,
Nik
http://www.bigaction.org/
|
|

October 14th, 2003, 02:58 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
Nik-
In my test of the code (after setting permissions) the incremented value did not update, but stayed at "1". I assume this is because the file size was not changing?? But after implementing cache control it worked. I'm, of course, not disputing what you're saying because I know this to be true too!
Jamal-
To further elaborate on setting permissions..
I addressed how to set write permissions in Windows XP in the thread that I posted. Provided that you are using XP to test the script (Or I should say I found one way of doing it, whether its the best way is another issue). If you are using a different OS and need to know how to set permissions, let us know what OS and someone will help you do it or point you to a tutorial.
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
|
|

October 14th, 2003, 05:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I just mentioned the permissions thing in case adding the cache control code didn't change anything.
Also -- it's not that the size of the file doesn't change. If the displayed value is always "1", then you can safely assume one of two things:
The PHP script is running, but can't read from and/or write to the file, so you always see the default "1" value. ($counter is 0 by default and incremented before being displayed)
The PHP script is NOT running because the browser pulls the page from the page cache. Also, we can assume that a request isn't even made of the web server -- after all, if the request *was* made of your web server, then it (the web server) would know that the .php extension signifies a script, and invoke the interpreter to generate the page.
Take care,
Nik
http://www.bigaction.org/
|
|

October 14th, 2003, 11:31 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
Well then the behavior of this script is particularly strange..
When I tested the script I noticed that the value was not incrementing. I cleared the cache then the updated value displayed correspondent to the number of times I clicked the refresh button. A further check of the created file in notepad revealed that it was in fact being changed. And worked as expected.
So the script does run... IE for some reason doesn't display the updated file. Something in there is making a decision to display the cache regardless of the script's output, that's why I thought it looked at the file size.
If I run the same script in Mozilla minus cache control it works perfectly. So it is specific to IE. I've tried playing with the cache configuration options in there but have come up null so far.
In fact file size doesn't even make sense because I've had problems in the past on other projects where PHP would output a parse error then I would go and fix the error and rerun the script and it would display the same error.. IE was going back to the cache.
I'm always have to clear the cache!
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
|
|

October 15th, 2003, 06:41 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Nik/Rich
Thanks for your advice on this, it turned out that the permissioning was not set correctly on the count.dat file, I thought that I had solved this by allowing full control to all users at the root (wwwroot) but this did not allow write access to the count.dat file itself. I also tried the header functions that you supplied prior to realising the permissioning issue, but that did not make any difference to the script.
Thanks again for all your help guys!!
Jamal
:D
|
|

October 15th, 2003, 12:17 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Wow. That *IS* weird. Damn IE!!!
Take care,
Nik
http://www.bigaction.org/
|
|
 |