Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/154704-redirect-stoped-by-echo/
Share on other sites

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.