Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Iowa City, IA
    Thanked 5 Times in 5 Posts

    Writing to a text file bombing out.


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

    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!

  • #2
    Master Coder
    Join Date
    Dec 2007
    Thanked 890 Times in 879 Posts
    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


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts