Jump to content

header redirect not working - no error


dflow

Recommended Posts

 

this code works

 

if i use the header() in the else section it doesnt but it will echo the commented part  :confused: :confused: :confused:

 

 

<?
/**
* User has already logged in, so display relevant links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
   echo "<li>Logged In ";
   echo "<b>$session->username</b></li>";
   if($session->isAdmin()){
      echo "<li><a href=\"LoginSystem/admin/admin.php\">Admin Center</a></li>";
   }
   
   echo "<li><a href=\"../LoginSystem/process.php\">Logout</a</li>";
}

else{header("Location: ../LoginSystem/main.php");
//echo "<li><a href=\"../LoginSystem/process.php\">Login</a></li>";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/223192-header-redirect-not-working-no-error/
Share on other sites

Comment out the current code, and put this in its place.

<?php
/**
* User has already logged in, so display relevant links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
echo "<li>Logged In ";
echo "<b>$session->username</b></li>";
if($session->isAdmin()){
	echo "<li><a href=\"LoginSystem/admin/admin.php\">Admin Center</a></li>";
}
echo "<li><a href=\"../LoginSystem/process.php\">Logout</a</li>";
} else {
//header("Location: ../LoginSystem/main.php");
//echo "<li><a href=\"../LoginSystem/process.php\">Login</a></li>";
if( headers_sent() ) {
	echo 'Headers already sent.';
} else {
	echo 'Headers not yet sent.';
}
}
?>

Comment out the current code, and put this in its place.

<?php
/**
* User has already logged in, so display relevant links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
echo "<li>Logged In ";
echo "<b>$session->username</b></li>";
if($session->isAdmin()){
	echo "<li><a href=\"LoginSystem/admin/admin.php\">Admin Center</a></li>";
}
echo "<li><a href=\"../LoginSystem/process.php\">Logout</a</li>";
} else {
//header("Location: ../LoginSystem/main.php");
//echo "<li><a href=\"../LoginSystem/process.php\">Login</a></li>";
if( headers_sent() ) {
	echo 'Headers already sent.';
} else {
	echo 'Headers not yet sent.';
}
}
?>

 

i get Headers already sent.

Nothing at all, not even white space can be sent to the browser before a header() redirect. You'll have to figure where the output is coming from and kill it before the redirect will work. Is there anything in a View -> Page Source?

Archived

This topic is now archived and is closed to further replies.

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