Jak mogę przekierować w PHP bez błędów nagłówka?
Jak mogę przekierować w PHP z poniższą konfiguracją bez otrzymywania błędów wyjściowych nagłówka, rozumiem, że nic nie może zostać wydrukowane w przeglądarce przed ustawieniem nagłówka, szukam rozwiązania, a nie wyjaśnienia, dlaczego tak się dzieje.
<?PHP
// include header
include ('header.inc.php');
// In my body section file if this is a page that requires a user be logged in then
// I run a function validlogin($url-of-page-we-are-on); inside of that file
//the function is below, it outputs a redirect to login page if not logged in
// include body of page we want
include ('SOME-FILE-HERE.php');
// include footer
include ('footer.inc.php');
// here is the function that is in the body pages, it is only called on a page that we require a logged in user so there are hundreds of pages that do have this and a bunch that don't, it's on a page to page basis
function validlogin($url) {
if ($_SESSION['auto_id'] == '') {
$msg = 'Please login';
$_SESSION['sess_login_msg'] = $msg;
$_SESSION['backurl'] = $url;
$temp = '';
header("Location: /");
exit();
}
}
?>
Chciałbym użytkownika funkcji nagłówka php, a nie przekierowania meta lub javascript
Również utrzymywanie listy stron, które wymagają logowania, nie jest tu możliwe, jeśli to możliwe