Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
rcgauer
New Member
New Member



Joined: Oct 26, 2004
Posts: 5

PostPosted: Tue Oct 26, 2004 4:14 pm Reply with quote

Hello,

I am new to this... and find PHP much easier to use on my remote server than on my local PC. (But that's a slow way to learn!)

Basic "hello world" and "phpinfo" scripts work fine locally, and phpinfo reports PHP 5 installed with lots o' goodies. I seem to stumble trying to open and/or read and/or modify files with PHP scripts.

This short script works fine on my server (and "counter.dat" exists, FYI, both locally and on server):

<?php
$counter_file = "count.dat";
if(!($fp = fopen($counter_file, "r"))){
die ("Cannot open $counter_file.");
}
$counter = (int) fread($fp, 20);
fclose($fp);

$counter++;

echo "You're visitor No. $counter.";

$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
?>


Does not work on my Win 2K local PC, however, with IIS running. Tried both with "counter.dat" and "C:\\Inetpub\\wwwroot\\etc..." as path to file. (Counter.dat is in same folder as script.)

Going from
ADMINISTRATIVE TOOLS |
INTERNET SERVICES MANAGER |
DEFAULT WEB SITE
to the specific folder, I have checked the Properties tab so that read, write, script source access selected for this subdirectory, and Execute Permissions set to "Scripts Only." No joy.

I am sure I am missing something somewhere.

All guidance welcome!

Thanks
rg

[/img]
 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Tue Oct 26, 2004 4:58 pm Reply with quote

You are probably also receiving a Permission Denied error message, correct? Please post the entire error message. It will tell you the line that the error is occurring on.


Last edited by Raven on Tue Oct 26, 2004 5:05 pm; edited 1 time in total 
View user's profile Send private message
sixonetonoffun
Spouse Contemplates Divorce



Joined: Jan 02, 2003
Posts: 2496

PostPosted: Tue Oct 26, 2004 5:01 pm Reply with quote

I was thinking he should use forward slashes in the path but yeah if the relative paths failing too....

_________________
[b][size=5]openSUSE 11.4-x86 | Linux 2.6.37.1-1.2desktop i686 | KDE: 4.6.41>=4.7 | XFCE 4.8 | AMD Athlon(tm) XP 3000+ | MSI K7N2 Delta-L | 3GB Black Diamond DDR
| GeForce 6200@433Mhz 512MB | Xorg 1.9.3 | NVIDIA 270.30[/size:2b8 
View user's profile Send private message
rcgauer







PostPosted: Tue Oct 26, 2004 5:10 pm Reply with quote

Here is the entire error message:

Warning: fopen(c:\Inetpub\wwwroot\DBTest\count.dat) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\DBTest\dbtest2.php on line 23

Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\DBTest\dbtest2.php on line 24

Warning: fclose(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\DBTest\dbtest2.php on line 25


I read that the double slashes were needed to escape the normal slash... That could just be hooey, or me not understanding the post, but it fails either way.

Thanks
rg
[/img]
 
Raven







PostPosted: Tue Oct 26, 2004 5:21 pm Reply with quote

Your script is not 23 lines long. Can you post the entire script? Double slashes are require with a backward slash but you can use the forward slashes and be done with it.
 
rcgauer







PostPosted: Tue Oct 26, 2004 6:09 pm Reply with quote

Here's the whole file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<?php
$counter_file = "c:\\Inetpub\\wwwroot\\DBTest\\count.dat";
if(!($fp = fopen($counter_file, "r"))){
die ("Cannot open $counter_file.");
}
$counter = (int) fread($fp, 20);
fclose($fp);

$counter++;

echo "You're visitor No. $counter.";

$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
?>



</body>
</html>
 
Raven







PostPosted: Tue Oct 26, 2004 6:16 pm Reply with quote

Let's verify that the file is being read. Change
Code:
$counter = (int) fread($fp, 20); 

fclose($fp);
to
Code:
$counter = (int) fread($fp, 20); 

die('$counter = '.$counter);
fclose($fp);

Does $counter have a value?
 
rcgauer







PostPosted: Tue Oct 26, 2004 6:35 pm Reply with quote

$counter = 0
 
Raven







PostPosted: Tue Oct 26, 2004 6:44 pm Reply with quote

But is there anything in the file itself, or is PHP defaulting?
 
rcgauer







PostPosted: Tue Oct 26, 2004 7:31 pm Reply with quote

When I download and use the counter.dat from the server, and use your new code --

$counter = (int) fread($fp, 20);
die('$counter = '.$counter);
fclose($fp);

-- I get a correct visitor counter number -- it reflects the most recent number from the server. So it reads the file...

My original code correctly increments the counter (so it gives me a counter number one greater than your code above) but is crearly not writing it back to the file.


In that instance, the output stream looks like this:

You're visitor No. 10.
Warning: fopen(c:\Inetpub\wwwroot\DBTest\count.dat) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\DBTest\dbtest2.php on line 23

Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\DBTest\dbtest2.php on line 24

Warning: fclose(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\DBTest\dbtest2.php on line 25


Same error.... So the counter increments, having read the file I guess, but it does not sucessfully write it. This is the behavior that led me to wonder about permissions....


THANKS
 
Raven







PostPosted: Tue Oct 26, 2004 7:36 pm Reply with quote

It's a permissions error on your winblows machine. I can't help you with that nor IIS. I would ditch IIS and install Apache.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©