Jump to content

Redirect Page in the middle of the script ["header("xx"); not working]


cjbeck71081

Recommended Posts

I was trying to validate a user input number against a database earlier, and i found a workaround that allows me to check if a directory exists and then do something based on that, and it works just as i want to.  However, what id like to do now, is have the page redirect based on the outcome of that code.  I tried using the header function, but It seems like it doesnt want to work in the middle of a code, so i was wondering if there was another way to redirect, instead of header, or to get header to work with this code.  Thank You. 

 

Code:

<?php
if (is_dir($dir)) {
header( 'Location: http://www.yahoo.com' );
} else {
mkdir($dir);
move_uploaded_file($_FILES['pic1']['tmp_name'], $uploadfile);
move_uploaded_file($_FILES['pic2']['tmp_name'], $uploadfile2);
move_uploaded_file($_FILES['pic3']['tmp_name'], $uploadfile3);
move_uploaded_file($_FILES['pic4']['tmp_name'], $uploadfile4);

mysql_query("INSERT INTO inv (vin, year, make, model) 
		VALUES ('$vin', '$year', '$make', '$model')");

header( 'Location: http://www.google.com' ) ;

}

?>

see:

http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

 

Also, if you want to redirect without using header() you could always do something like this

 

<?php
    echo "<script language='javascript' type='text'/javascript'>location.href='url_to_redirect_to.php'</script>";
    exit();
?>

 

Remember though, that won't work for people who turn javascript off or don't have it available.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.