Redirection is a redirection; -)
If you tell the browser using the Location: header to redirect to another page, the browser does just that: it redirects to another page. And the browser does it immediately - without any delay.
Therefore, your echo will not be displayed at all.
Set the headers first
In addition, you need to set headers before each other output operation (as indicated by Fred -ii- ):
// First, echo headers header("location: login6.php"); // Then send any other HTML-output echo "Please Log In First";
Better not use auto-redirects
It is likely that you will not see the message, and then - after a certain time - automatically redirect to another page. People can get confused in this process. . Better do this:
Show the login page and representing the custom hinter or error message on this page.
Common decision
Prepare the component in the user session containing the information that will be displayed in the next instance of the script . This component can be a list of such messages:
$_SERVER[ 'sys$flashMessagesForLater' ] = array( "Sorry, userID and password didn't match.", "Please login again." );
Each time a script request comes in , check if $_SERVER[ 'sys$flashMessagesForLater' ] non-empty array.
If so, output these values ββto a clearly defined one located on the generated HTML page. A clearly defined location will always be in the same place, somewhere at the top of each page. You might want to add an error message box.
You might want to prepare the class as follows:
class CFlashMessageManager { static public function addFlashMessageForLater( $message ) { $_SERVER[ 'sys$flashMessagesForLater' ][] = $message; } static public function flashMessagesForLaterAvailable() { return isset( $_SERVER[ 'sys$flashMessagesForLater' ] ) && is_array( $_SERVER[ 'sys$flashMessagesForLater' ] ) && ( 0 < count( $_SERVER[ 'sys$flashMessagesForLater' ] )) ; } static public function getFlashMessageForLaterAsHTML() { return implode( '<br />', $_SERVER[ 'sys$flashMessagesForLater' ] ); } }