Bman900 Posted April 19, 2009 Share Posted April 19, 2009 Here is my code: <?php $question = $_POST['question']; $firstname = $_POST['name_first']; echo "you question is $question"; sleep(5); if (strstr($question, "house")) { Header("Location:page1.php"); } else { echo "$question"; } ?> I want echo "you question is $question"; to run for 5 seconds and than move on to my if statement. Well when I run this it just stops after the sleep and the if statement is not run. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/154704-redirect-stoped-by-echo/ Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 read the big capitalized sticky about header errors. http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/154704-redirect-stoped-by-echo/#findComment-813494 Share on other sites More sharing options...
Bman900 Posted April 19, 2009 Author Share Posted April 19, 2009 I see the problem now, i will probably need to redirect multiple times. This is how my code looks like now: <?php $question = $_POST['question']; $firstname = $_POST['name_first']; if (strstr($question, "house")) { Header("page1.php"); } elseif (strstr($question, "foreclosure")) { Header("page2.php"); } elseif (strstr($question, "bankruptcy")) { Header("page3.php"); } else { Header("default"); } ?> Is there another function that will redirect to a url in an if statement? Quote Link to comment https://forums.phpfreaks.com/topic/154704-redirect-stoped-by-echo/#findComment-813499 Share on other sites More sharing options...
Bman900 Posted April 19, 2009 Author Share Posted April 19, 2009 nvm I got it, am using echo "<meta http-equiv=\"refresh\" content=\"0;URL=page1.php\">"; Quote Link to comment https://forums.phpfreaks.com/topic/154704-redirect-stoped-by-echo/#findComment-813513 Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 no. well, you can echo out a regular html meta redirect if you want... but you could rethink how you've got it setup in the first place to reduce those conditions. You can - make the form values for $_POST['question'] the same as the page names you want to redirect to. Like, make the values page1, page2,page3 (or just 1,2,3) and do: header("Location: " . $_POST['question'] . ".php"); or header("Location: page" . $_POST['question'] . ".php"); depending on the value. You can - make an array like so: $pages = array('house' => page1.php, 'foreclosure' => page2.php, 'bankruptcy' => page3.php); header($pages[$_POST['question']); Point being is that you don't need to make a condition for every option. Quote Link to comment https://forums.phpfreaks.com/topic/154704-redirect-stoped-by-echo/#findComment-813516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.