cjbeck71081 Posted April 19, 2007 Share Posted April 19, 2007 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' ) ; } ?> Link to comment https://forums.phpfreaks.com/topic/47731-redirect-page-in-the-middle-of-the-script-headerxx-not-working/ Share on other sites More sharing options...
Michael Lasky Posted April 19, 2007 Share Posted April 19, 2007 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. Link to comment https://forums.phpfreaks.com/topic/47731-redirect-page-in-the-middle-of-the-script-headerxx-not-working/#findComment-233143 Share on other sites More sharing options...
cjbeck71081 Posted April 19, 2007 Author Share Posted April 19, 2007 Thanks it worked perfect. Link to comment https://forums.phpfreaks.com/topic/47731-redirect-page-in-the-middle-of-the-script-headerxx-not-working/#findComment-233198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.