2

I've looked at several of the "PHP redirect not working ......" posts, but I haven't had any luck figuring out what is going on with my problem.

The code below always goes to teacherActivity_2.php even though the 2nd if passes and should redirect to teacherActivity_3_shadowT.php. If I comment out the teacherActivity_2.php, the page redirects (as expected) to teacherActivity_3_shadowT.php. I think I'm missing some obscure rule that I should know but don't. Any ideas?

Why does this redirect to teacherActivity_2.php instead of teacherActivity_3_shadowT.php?

if($test == 'yes') {
  if($_SESSION['wblReporting']['activity'] == 'shadowT'){
  header('Location: /app/do_cte-wbl/forms/teacherActivity_3_shadowT.php');
  }
header('Location: /app/do_cte-wbl/forms/teacherActivity_2.php');
}
?>
1
  • 2
    Try to add die(); after this line header('Location: /app/do_cte-wbl/forms/teacherActivity_3_shadowT.php'); Commented Feb 7, 2020 at 5:41

1 Answer 1

2

Try the following:

if($test == 'yes') {
  if($_SESSION['wblReporting']['activity'] == 'shadowT'){
    header('Location: /app/do_cte-wbl/forms/teacherActivity_3_shadowT.php');
    die();
  } else {
    header('Location: /app/do_cte-wbl/forms/teacherActivity_2.php');
    die();
  }
}

This worked no matter how many elseifs I used.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.