Jump to content

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?

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.