Page 1 of 1
header() issues
Posted: Tue Feb 11, 2003 1:54 am
by moniarde
I am trying to do a simple redirect, but am having some serious issues with it all. No matter what I do, everytime I try to use header(), I get this message.
(I've changed the file info)
Warning: Cannot modify header information - headers already sent by (output started at drive:/host/folder/filename.php:10) in drive:/host/folder/filename.php on line 14
I've checked this syntax over and over and there doesn't seem to be anything wrong with it. Here's the code.
Code: Select all
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
$testvar = "this has worked.";
header("location: http://%sheader.php" .$_SERVERї'HTTP_HOST']);
exit;
?>
</body>
</html>
The variable is just to test that it will pass a variable through.
Does anyone have any ideas?
Posted: Tue Feb 11, 2003 2:09 am
by crazyjimsmith
Im not an expert but I do recall reading some of the read these first posts at the top of the forum.
Your header info needs to be placed before any code.
Posted: Tue Feb 11, 2003 3:10 am
by twigletmac
reply
Posted: Tue Feb 11, 2003 4:14 am
by moniarde
OK, thanks for the reply, and I understand now that I need to be careful what i can use before I use a header tag.
The problem I have though, is that I tried to do the same thing WITHOUT trying to create the variable, and it still did it. I commented it out, I deleted it, I tried renaming the file, but it still didn't work. Any ideas?
Posted: Tue Feb 11, 2003 4:56 am
by twigletmac
It's not creating the variable which is causing the problem, it is the HTML that you are outputting to the browser beforehand:
Code: Select all
html>
<head>
<title>Untitled</title>
</head>
<body>
You cannot have any output before you try and use the header() function.
Mac
Posted: Tue Feb 11, 2003 6:04 am
by moniarde
No luck with deleting anything before header(). Here's the code I have:
Code: Select all
<?
header("location: http://%sheader.php" .$_SERVERї'HTTP_HOST']);
?>
This is everything in the file.
Posted: Tue Feb 11, 2003 7:14 am
by twigletmac
Are you still getting the same error or is it not working in a different way?
Mac
Posted: Tue Feb 11, 2003 7:27 am
by moniarde
Well, after I sent that last post, about 5 mins after I first deleted everything, it decided it was going to work, and since then I've been testing it with everything I can to make sure it's going to hold up. I'm currently using output buffering to make sure it holds up. And so far it is. Thanks all for you help.
header issue
Posted: Sun Feb 16, 2003 9:46 am
by shareaweb
you must use output bufferring in this case since you already sent html tags to the browser (and hence a header..) or you can switch to meta tag refresh
ob_start();
/* code here */
ob_end_flush();
All you worries go away this way

Re: header issue
Posted: Mon Feb 17, 2003 2:45 am
by twigletmac
shareaweb wrote:you must use output bufferring in this case since you already sent html tags to the browser (and hence a header..) or you can switch to meta tag refresh
or you can just make sure you don't output anything to the browser before you try and use the header() function, not every circumstance requires output buffering.
Mac