headers already sent - please explain
Posted: Tue Mar 29, 2011 5:51 pm
1. I'm a newb
2. Can someone please explain what it means when you get an error saying headers are already sent (theory please). I am trying to use a function to verify if a user has access to a certain page.
3. Most of my pages start like this:
4. These are the two functions that confirm and then redirect if needed:
5. Thank you (again)
2. Can someone please explain what it means when you get an error saying headers are already sent (theory please). I am trying to use a function to verify if a user has access to a certain page.
3. Most of my pages start like this:
Code: Select all
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php //if I comment out this line , no error
confirm_logged_in("contributor"); ?>
<?php include("includes/header.php"); ?>Code: Select all
function confirm_logged_in($x) //gets called from session.php - see above
{
$query = "select `admin` from `users` where `user_id` = '".$_SESSION['user_id']."'";
$result = mysql_query($query, $connection) or die(mysql_error());
if(mysql_num_rows($result)==0 || admin != $x)
{
redirect_to("index.php");
}
}
function redirect_to( $location = NULL ) { // gets called from functions.php - see above
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}