Header and redirect

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

Post Reply
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Header and redirect

Post by Darkside »

Its seem my header will not work? I'm including this file into my site layout and thats wot i think is makin the error as it works when i just open the file outside of the layout. I've use loads of header's in my site and they all work but this 1 doesnt?

Code: Select all

<?php
$uspass = stripslashes($uspass);
include ("owe.php");
$pass = "clbob";
if (!("$uspass" == "$pass")) &#123;
Header ("Location: ../../index.php?folder=message&page=thanks");
&#125; else &#123;
&#125;
?>
is there an easy answer? or anything else i can use instead of Header?

I guess you will all notice there there is nothing in else but this is because its for a post pages and all my post get add to my page in html below this code so thats not importent?

Please help.
User avatar
skehoe
Forum Commoner
Posts: 59
Joined: Sun Dec 22, 2002 5:57 am
Location: Denver

Post by skehoe »

Make sure you're not sending any output to the browser prior to the redirect (even headers). Also make sure that your not accidentally sending any blank lines or characters. Hope that helps.
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Post by Darkside »

//my error?

Warning: Cannot add header information - headers already sent by (output started at /fileserver/webserver/no-order/index.php:6) in /fileserver/webserver/no-order/_message/posts.php on line 6
hurkle
Forum Newbie
Posts: 15
Joined: Tue Feb 11, 2003 1:21 pm
Location: Minnesota, USA

Post by hurkle »

this might help.. near the start of each script, place this..

Code: Select all

ob_start();
and towards the end, this

Code: Select all

ob_end_flush();
ob_start(); basically starts saving all the output that your script creates, and places it into a buffer. When your code is all done, and hits the ob_end_flush statement, it spits it all out at once. I've found this to be a big help, especially when doing header_location calls, and content_type stuff.

Hope this helps..
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

worked like a dream

Post by Darkside »

its works like a dream..

You dont think it will naf up any of my post scripts do you? dont want to fix 1 problem but make more.

thanks anyway :P
User avatar
moniarde
Forum Newbie
Posts: 20
Joined: Thu Feb 06, 2003 12:45 am
Location: Perth, Western Australia

Post by moniarde »

I had a similar problem the other day. You'll find the answer in one of the first few posts, called, "Sticky: Before Post Read: Warning: Cannot add header information." It's all there - believe me. And really, it is that simple.
hurkle
Forum Newbie
Posts: 15
Joined: Tue Feb 11, 2003 1:21 pm
Location: Minnesota, USA

Post by hurkle »

Darkside, I've been using the ob start and ob end flush in all my php code, and haven't had any downsides. I've also used the ASP equivalent that does the same thing, and nothing bad has ever come of it.

The only time I don't use it is in rare instances when I want to display insane amounts of data, i.e. one asp project has a page that displays a dump of a database with 400 columns and about 20000 rows.. Not locking the buffer lets you see visible progress as the whole thing is being sent. But 99% of the time, it seems like a good thing to use.
Post Reply