forms not working from non-local machine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

forms not working from non-local machine

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

check the permissions you should.

grant modify privileges to IUSR_machinename you should.
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

know what owt stand for I do not.

change the permissions on the window's folders themselves you need.
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

Hi Burrito,
I am using Integrated Windows Authentication, so should this really apply?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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.
Post Reply