Page 1 of 1

forms not working from non-local machine

Posted: Wed Dec 14, 2005 10:21 am
by mesz
I have a php website running on IIS on my Windows XP laptop (I wish it was apache too).
When I use a php form to update my flat file db from this local machine, it works with no problems.
However when associates on the same network (but different machines) try to use the form they get this error -
Warning: fopen(news.txt) [function.fopen]: failed to open stream: Permission denied in C:\Source\dir\org\dir\action.php on line 16
Sorry couldn't open file

Warning: fclose(): supplied argument is not a valid stream resource in C:\Source\dir\org\dir\action.php on line 63
This is the form -

Code: Select all

<?php 
$fp = fopen('news.txt','a'); 
if ($fp=="") { 
    	echo "Sorry couldn't open file<br>"; 
} else { 
if ($_POST['images']=="") { 
        	echo "<div class=\"button1\">please <a class=\"button1\" href=\"javascript:history.go(-1)\">
        	<b>go back</b></a>and add image link.<BR><i>the animals are important</i>.</div>\n\n"; 
} else { 
if ($_POST['news']=="") { 
        	echo "<div class=\"button1\">please <a class=\"button1\" href=\"javascript:history.go(-1)\">
        	<b>go back</b></a>and add some details.<BR><i>the details are important</i>.</div>\n\n"; 
} else {
if(strstr($_POST["news"],"&")) {
	echo "<div class=\"button1\">the text cannot contain the ampersand symbol - &<a class=\"button1\" href=\"javascript:history.go(-1)\">
        	<b>please go back</b></a>and correct.<BR><i>these things are important</i>.</div>\n\n";

} else {
if(!strstr($_POST["images"],"[img]")) {
	echo "<div class=\"button1\">the images link must be formatted correctly<br>ie - contain '<b></b>
	<br><a class=\"button1\" href=\"javascript:history.go(-1)\">
        	<b>please go back</b></a></div>\n\n'";
} else {
if (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $_POST['email'])) {
   	echo "<div class=\"button1\">invalid e-mail address<br><a class=\"button1\" href=\"javascript:history.go(-1)\">
        	<b>please go back</b></a></div>\n\n";

}else {
        	$line = date("d.m.y") . "¬" . $_POST['name'] . "¬".$_POST["email"] . "¬".trim($_POST["subject"]). "¬".$_POST["url"]. "¬".$_POST["images"]; 
      	$line .= "¬" . $_POST['news']; 
        	$line = str_replace("\r\n","<BR></BR>",$line); 
       	$line = str_replace(" < "," LESS THAN ",$line); 
        	$line = str_replace(" > "," GREATER THAN ",$line); 
        	$line = str_replace(" >= "," GREATER THAN OR EQUAL TO ",$line); 
        	$line = str_replace(" <= "," LESS THAN OR EQUAL TO ",$line); 
       	$line = str_replace(" & "," and ",$line); 
        	$line = str_replace("&","and",$line); 
       	$line = stripslashes($line); 
        	$line .= "\r\n"; 
        	fwrite($fp, $line); 
	echo "all sorted...cool<br>
	<a href=\"javascript:self.close()\"><small>close window</small></a>";
    } 
} 
}
}
}
}
if(!fclose($fp)) { 	
} 
?>
What is wrong?

The file 'news.txt' is in the same directory as the php file containing the above code.

Posted: Wed Dec 14, 2005 10:40 am
by Burrito
check the permissions you should.

grant modify privileges to IUSR_machinename you should.

Posted: Wed Dec 14, 2005 1:08 pm
by mesz
thanks for answering.
one thing (and this is off the top of my head, I haven't googled owt yet)...
is that an IIS or php config thing?

cheers mate

Posted: Wed Dec 14, 2005 2:40 pm
by Burrito
know what owt stand for I do not.

change the permissions on the window's folders themselves you need.

Posted: Thu Dec 15, 2005 6:46 am
by mesz
Hi Burrito,
I am using Integrated Windows Authentication, so should this really apply?

Posted: Thu Dec 15, 2005 7:14 am
by Chris Corbyn
mesz wrote:Hi Burrito,
I am using Integrated Windows Authentication, so should this really apply?
Yes... look under the security tab on the folder properties... the error means that the IIS user ( IUSR_<YOUR MACHINE> ) does not have write-permissions to the folder ;)

Posted: Thu Dec 15, 2005 11:25 am
by mesz
cheers guys, I haven't sorted it yet, but I think you have put me on the right road.
I need to mess around with security rights...so I guess I'll just plow on with that and let you know when it has worked.
cheers.