-1

I do not understand why it does not redirect to the page that I ask, I have hours trying to redirect and I do not get it to work, I am trying to know in a URL the ID parameter, otherwise I redirect to the page, but this does not work, I have others redirect codes but all have exit ();

if (isset($_GET['id'])) {
//ok show de page
}else{
header('location: pages.php');
exit();
}

Note: if in the else I put echo "no id"; it works.

Any ideas, thank you!

David Noriega
  • 153
  • 1
  • 11

2 Answers2

1

Make sure that you call header('location: pages.php'); before you (printf/echo/generate any output) on the screen; changing the header location must be before printing anything on the page.

Abozanona
  • 2,261
  • 1
  • 24
  • 60
1

Could you please try with following structure (Try putting all your code between ob_* functions as mentioned following )

<?php
ob_start();
...
header('Location: pages.php');
...
ob_end_flush();
?>

It would just make sure you dont send anything before calling header function. For more information, Please check PHP documentation for ob_* function.

Tarun
  • 3,162
  • 3
  • 29
  • 45