Header query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leoden
Forum Newbie
Posts: 21
Joined: Sat May 24, 2003 8:48 pm

Header query

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post 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();
?>
Post Reply