Hi! Im having some problems with getting a redirect to work and for the life of me i have no idea why. Ive got a function been pulled in from a separate php page, and ive also got a session page all set up.

What i want to happen is for the page to redirect to login if you try to get to a page that you have got to by logging in.
Basically when i clear cookies and refresh staff.php i get this message:

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\widget_corp\includes\header.php:10) in C:\wamp\www\widget_corp\includes\functions.php on line 23

line 23 is this part: header("Location: {$location}");

Here are the function and staff page code:

function.php:

function redirect_to( $location = NULL ) {
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}

staff.php:

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
<?php
if (!isset($_SESSION['user_id'])){
redirect_to("login.php");
}
?>

Be great if anyone could shed some light on this. Thanks!

    Write a Reply...