Page 1 of 1

Redirect warning

Posted: Thu Apr 29, 2010 12:24 pm
by scorp54
Howdo,
I've been searching everywhere and trying everything so far to no avail.
This is the error message I'm getting while logging in:
Warning: Cannot modify header information - headers already sent by (output started at /home/param/public_html/edit/includes/header.php:8) in /home/param/public_html/edit/includes/functions.php on line 33.
I can hit refresh on the browser and then resent and everything works fine from that point on. Also the code works flawlessly on my local drive.

This is the code area in question for header.php, there actually is no php here so I don't understand why the warning is pointing here.

Code: Select all

6. <link href="styles/public.css" media="all" rel="stylesheet" type="text/css" />
7. </head>
8. <body bgcolor="#cfcfcf">
9. <table width="1000" border="0" cellspacing="0" cellpadding="0" align="center">
Code for functions.php. I have no trouble going to other pages once I'm in.

Code: Select all

31.	function redirect_to( $location = NULL ) {
32.		if ($location != NULL) {
33.			header("Location: {$location}");
34.			exit();
35.		}
36.	}
Just for good measure, the session code which is called from every page.

Code: Select all

<?php require_once("includes/functions.php"); ?>
<?php 
	session_start();
	
	function logged_in() {
		return isset($_SESSION['user_id']);
	}
	
	function confirm_logged_in() {
		if (!logged_in()) {
			redirect_to("login.php");
		}
	}
?>
Things I have done:
Made sure the session call is the first thing on the pages.
Made sure there is no white space before the session calls.
Copied the code from Dreamweaver, pasted it into Notepad and save as ANSI.
Pulled out a lot of hair. :banghead:

Re: Redirect warning

Posted: Thu Apr 29, 2010 12:37 pm
by Christopher
You are outputting a carriage return between the two PHP blocks. ANY output will cause header to be sent.

Code: Select all

<?php require_once("includes/functions.php"); ?>
<?php 

Re: Redirect warning

Posted: Thu Apr 29, 2010 2:25 pm
by scorp54
Sorry, that seems to make no difference unless putting it together like below isn't what you're getting at.

Code: Select all

<?php 
	require_once("includes/functions.php");
	session_start();
Thanks for the replay.

Re: Redirect warning

Posted: Thu Apr 29, 2010 3:24 pm
by Christopher
Either that:

Code: Select all

<?php 
	require_once("includes/functions.php");
	session_start();
Or this:

Code: Select all

<?php 
	require_once("includes/functions.php");
?><?php
	session_start();
There just can be ANY output -- even whitespace -- before you call functions that send headers like header() or session_start().

Re: Redirect warning

Posted: Thu Apr 29, 2010 5:33 pm
by scorp54
Yea, that didn't work but I found a cheat that took care of the problem.
Put a php.ini file in the offending area with "output_buffering = On" written in it.
Thanks for your help though.