Php redirect

ok so i have a website that sends data to a datahandler which writes it to a txt document but before it does this i want it to validify that they entered the CAPTCHA correctly and if not redirect to an error page otherwise i want to redirect back to the homepage in the php code. but when i try running it the header function isnt working i read online that it didnt work with submitted data but i couldnent find anyway around that if its possible

heres the code
$number = $_POST[‘number’];
$name = $_POST[‘inpUsername’];
$post = $_POST[‘inpComments’];
if ($number != $one + $two){
header(‘Location: errorindex.php’);
} else {
$file = “text.txt”;
$oldcontents = file_get_contents($file);
$fpost = “$name: $post
$saved_file = fopen($file, ‘r+’);
fputs($saved_file, $fpost);
header(‘Location: index.php’);
} //end if

Try the header function with a fully qualified url.

i tried the url like that at first and when it didnt work i tried it like this. so i dont think its that. i think ithas something to do wth me outputing data before the header is called but im not sure exactly what this means and how to fix it.

If you write to the page before you call the header() function, even if it is an empty space, then calling header() will generate an error. Check to make sure you don’t even have a blank line output to the page anywhere. In the below example, you will see that there is a blank line before I open <?php. This header example will not work because of that blank line.

header( 'location: index.html' );

The fact that you’re using $one and $two without defining them indicates we’re not being shown the full code, so i’m guessing Tink has hit upon the correct issue.

ok Tink you were dead on i was outputting information except like Starlion said it was more than just a bklank page so i ended up just doing an html redirect

for anyone who is still wonder how to fix this change the header line to

echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=errorindex.php">;';