Forum Moderators: coopster

Message Too Old, No Replies

PHP Header Not Redirecting

         

sitemaker

4:20 pm on Jul 29, 2005 (gmt 0)

10+ Year Member



Hi All,

I am using this simple script to store newsletter subscribers in a .txt file (not confident enough for SQL yet).

Code:

<?php {
$emailAddress = $_POST['em'];
$filename = "subscribers.txt";
$content = "$emailAddress\n";
$fp = fopen($filename, "a");
$fw = fwrite( $fp, $content );
fclose( $fp );
header("Location: [#*$!xx.co.uk...]
}?>

While the email address storage function is working fine, I'm not being redirected to my thank you page afterwards (browser stays at the mailhandler script, which is of course a blank page...

Can anyone point out what I've done wrong?

Regards,

StupidScript

5:38 pm on Jul 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your use of curly braces is questionable ... there's no need for them.

sitemaker

8:01 pm on Jul 29, 2005 (gmt 0)

10+ Year Member



Thanks, I tried removing them but am still stuck with the same problem.

Anybody else?

StupidScript

11:58 pm on Jul 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, that was the simple answer ...

Even more simple: In that we can't see the entire file from which your code snippet comes, there must be no output at all before invoking a header() (and other similar) function. The

<?php
must be the very first line, and there must not be any extra spacebars in your script (like at the end of a line before the carriage return) before the header() function.

More complicated is the idea that your file writing operation may be dumping stuff into the buffer, which is also a problem for the header() function.

Of course (as you already have) check the PHP manual page for header() [us3.php.net] to make sure you are following all of the rules. It's usually something simple.

sitemaker

12:33 am on Jul 30, 2005 (gmt 0)

10+ Year Member



Thank you very much. It finally works, I had a couple of extraneous spaces in.