Page 1 of 1

Header query

Posted: Tue Oct 21, 2003 12:41 pm
by leoden
Can someone give me some advice. At the top of my login page I have the following

Code: Select all

<?php
require('db_connect.php');
	if($logged_in == 1) &#123;
		header('index.php');
		die();	
	&#125;
?>
Question 1 : Do I need the die()? ( I presumed I needed to stop the rest of the page being read )

Question 2 : Do I need to specify Location? ( It does work as is)

Thanks in advance

Posted: Tue Oct 21, 2003 12:45 pm
by markl999
Just depends how 'correct' you want to be. Some browsers are abit anal about headers. I tend to always do:

Code: Select all

header("Location /index.php");
exit;
The exit just ensures processing stops, just in case the header 'fails' for whatever reason.

Posted: Wed Oct 22, 2003 12:33 am
by Kriek
Leoden, in most cases the header() function's location response-header field requires scheme, hostname and absolute path.

Code: Select all

<?php
    ob_start();
    $dom = $_SERVER&#1111;'SERVER_NAME'];
    require_once('db_connect.php');
    if ($logged_in == 1 && !headers_sent()) &#123;
        header('Location: http://' . $dom . '/index.php');
        exit();
    &#125;
    ob_end_flush();
?>