View Full Version : Writing to a text file bombing out.

11-05-2009, 07:14 PM

I have two site with distinctly identical coding behind a page. it is this on my unsubscribe page:
if (! $_POST["email"] || strlen($_POST["email"]) == 0 || strpos($_POST["email"], "@") == 0)
else {
$handle = @fopen("../logs/unsubscribes.txt", "a");
fputs($handle, $_POST["email"] . " " . "\r\n");
fclose ($handle);

echo 'Thank you, you have been unsubscribed';
exit; }

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my page</title>

<script type="text/javascript">
function validateForm(form)
var emRE = /^[\w\-\'\.]+\@([\w\-\']+\.)+[a-z]{2,6}$/i;
if ( ! emRE.test( form.email.value ) )
alert("Please enter a valid email address");
return false;
return true;



<form action="" method="post" name="frm" onsubmit="validateForm(this)">

<center><br />
Enter Your Email Address:<br />
<input type="text" id="email" name="email" />
<center><input type="submit" id="unsubscribe" value="Unsubscribe Me" /></center>

</html>on one of my websites, this works perfectly, and on the smaller one, the PHP at the top throws an "invalid stream resource" error at me. I assume the stream is the text file I am writing to. There is the same error occuring on two lines. One is fputs() and the other is fclose(). I know the text file is in the right place and the syntax for locating it is also correct. Can someon identify a problem here please? thanks for any help!

11-05-2009, 07:23 PM
check $handle to be valid before you use it, also check permission and see if fopen and friend are not disabled. If still don't work, check path and file again.
I would remove @ to see what fopen say about this, :)

best regards