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
leoden
Forum Newbie
Posts: 21 Joined: Sat May 24, 2003 8:48 pm
Post
by leoden » Tue Oct 21, 2003 12:41 pm
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) {
header('index.php');
die();
}
?>
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Oct 21, 2003 12:45 pm
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.
Kriek
Forum Contributor
Posts: 238 Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:
Post
by Kriek » Wed Oct 22, 2003 12:33 am
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ї'SERVER_NAME'];
require_once('db_connect.php');
if ($logged_in == 1 && !headers_sent()) {
header('Location: http://' . $dom . '/index.php');
exit();
}
ob_end_flush();
?>