Good day!

Could somebody help me with this problem:
When i'm using header() to redirect page it giving me error message like this:
Warning: Cannot modify header information - headers already sent by (output started at /exxport/www/httdocs/waff/teng/HTML/Jobss/loginn_hrm.ph
p:10) /exxport/www/httdocs/waff/teng/HTML/Jobss/loginn_hrm.phpon line 336

Thanks...

Roland (rcasinillo_s)

use header() at top of page ( HTML ) that u redirect or u will have that error !!!
header(); <html>
nor <html> header();
oke !!!

use header() at top of page ( HTML ) that u redirect or u will have that error !!!
header(); <html>
nor <html> header();
oke !!!

Thank you for your responsed, but still not working I'm thinking may be it conflicts with the session_start() that i have placed on the top of the page code. What do you think?

Or is there any methods, ways to use as page redirection besides, header() function?

Is there anybody could help!

Roland

can u post your code here ??

header() doesn't have to be at the very top of your code but it does have to be before there is even one character sent to the browser. This might be a blank line before the <?php or maybe you include header.php before you process the page - well you can't do that if you want to keep your options open.

header() doesn't have to be at the very top of your code but it does have to be before there is even one character sent to the browser. This might be a blank line before the <?php or maybe you include header.php before you process the page - well you can't do that if you want to keep your options open.

Thanks Sarahk! excellent....

Roland

use header() at top of page ( HTML ) that u redirect or u will have that error !!!
header(); <html>
nor <html> header();
oke !!!

Thank you Kulinh, you're right! My code is now working....

Thank you...Thank you...Thank you...

Roland

Here's how header() works

You can put header("Location: whateverpage.php"); anywhere you want. Top/bottom of script doesnt matter. What is important is to put exit(); right after. The reason being that all your doing with the header call is changing the headers, the script wants to finnish before it uses those new headers. So if you stop the script then you will redirect the page.

Also, if you tried echoing or printing anything to the screen before header(), then it wont work because you're basiclly trying to say you want a page returned to the user yet you also want to go to another page. When you echo, you are saying that the current heading is what you want. So thats why when you change the heading later it says "Cant change header"

-B

like sarahk said, as soon as their is some http output, you cannot modify the headers. This is a restriction of the http protocol.
PHP can also buffer http output and only send the output when you want it to using the ob_start() and ob_end_flush().

This is also useful in many other situations, but especially in yours where you want to modify the http header information anywhere withing the script.

so if you call ob_start(); on the first line of your executing php file, then whenever you want to make a header redirect, you just call header() then exit();.

note: I believe exit will automatically flush the http headers. If not then you have to call ob_end_flush(); before exit.

Hello all here on DW, and even though I've popped in here a couple of times...this is my first post.

I also do know want you to think I am "hijacking a thread", but I also am having a

header("Refresh: 1;url=http://www.TheWebsite.com/thankyou.php");

problem that is beating me up.

Instead of creating a new thread, like most others like..I personally feel that keeping a subject "on a direct topic" is best, as searching thru a forum...for a subject with the same topic...and reading them all, well.. I feel redundancy.

I will be more than happy to if required though.

My problem

I am also getting the error, in a normal situation doing "page by page", it isn't a problem, but I am trying to redirect after a "form submit" that is placed globally in the left pane of the site. (ie...displayed on all pages of the site, and pulled with what the original programmer used as "left.php"

The form it self, is submitted then into /js/ajax_form.php in which I have tried all the above...and still get this error.

file "left.php" (in which is all html) and I place it...no errors, and does nothing.

I am really lost on this one, and am thinking I am going to have to place it globally?

Thx for taking the time to read this,

T~

So, if I am understanding you correctly, you:
have a form
you submit the form
the form goes to /js/ajax_form.php
user redirected (I think this is the step where you want the redirect to happen)
Instead of a redirect you are getting the headers already sent error

I am not fully understanding the left.php. Is that the file that the form is contained in? Is it the previous file used to redirect?

Usually the most common problem with a header redirect is that something else is sent to the page before the header.
Nothing at all can be sent before the redirect. There can be no whitespace, no html, no characters at all can be sent to the screen. It also needs to be before any include,require, or any other file access functions are called.

Just in case, here is the link to the PHP manual for headers:
http://us2.php.net/header

Speak of the devil!! Just a joke, as I got it about 15 minutes to work (somewhat)

But I thank-you so much for the reply.. !! BUT? (Please see below)

So, if I am understanding you correctly, you:
have a form
you submit the form
the form goes to /js/ajax_form.php
user redirected (I think this is the step where you want the redirect to happen)

Yes...

I am not fully understanding the left.php. Is that the file that the form is contained in? Is it the previous file used to redirect?

Yes, in a normal "step-by-step" app, refreshing to another page has never been a problem for me... It's just that the contact form is on every page...etc...sode, form code actually located at the (2) stated.

Just in case, here is the link to the PHP manual for headers:
http://us2.php.net/header

This where I ended up, and solve...but I had just got exposed to this site code yesterday afternoon ( the one where I am having a problem), and I left the "easiest" (what I thought for last...lol...till this am.)...And getting flustered ( and jacked up on Coffee)

ob_start() resolved it, but it does not "load the top of the page" after from submit... Do I need to ob_end_flush() at the end of this now please?

This is my only problem at the moment...The other thing is, it's not one of my servers...and I had no php.ini control over output buffer in it, and was: output_buffering no value no value and I had been waiting to hear back about if/if not I should try to override it.

I have not had to use the ob_ functions yet but I did take a quick look at:
http://us.php.net/ob_end_flush

It seems that ob_end_flush is not needed as PHP will do this itself if ob_start has been called. However, from reading the description of the function I would still put it in and see if it helps you.

As for just being exposed to someone else's code.. lol .. if it were me and I had the time, I might just scrap all of it and start again.

Anyways, sorry I cannot be of more help on this matter, I haven't had to deal with this type of issue with my site yet hehe.
Good luck and I hope you get it all figured out!

OK, I must have lied...or been seeing things...and doing my form submit...from the page I was trying to redirect to...<sigh>

BAck to square one... If I use ob_start() in my ajax_form.php which is where the "action" takes place... I don't get the error...

But the page does not redirect...

No matter what page I am in...it stays there..

This is driving me nuts!!

He's got to be calling a JS or soemthing...that's possibly over ridding what I am doing?

Is that possible?

Hello all here on DW, and even though I've popped in here a couple of times...this is my first post.

I also do know want you to think I am "hijacking a thread", but I also am having a problem that is beating me up.

Instead of creating a new thread, like most others like..I personally feel that keeping a subject "on a direct topic" is best, as searching thru a forum...for a subject with the same topic...and reading them all, well.. I feel redundancy.

I will be more than happy to if required though.

My problem

I am also getting the error, in a normal situation doing "page by page", it isn't a problem, but I am trying to redirect after a "form submit" that is placed globally in the left pane of the site. (ie...displayed on all pages of the site, and pulled with what the original programmer used as "left.php"

The form it self, is submitted then into /js/ajax_form.php in which I have tried all the above...and still get this error.

file "left.php" (in which is all html) and I place it...no errors, and does nothing.

I am really lost on this one, and am thinking I am going to have to place it globally?

Thx for taking the time to read this,

T~

Hi T,

The headers mentiond here are HTTP Headers. I think you got it confused with the HTML HEAD tags. (This is often confused).

The HTTP Header is "Location: http://example.com/" where "http://example.com/" is the URL you want to redirect to.

So if you want to redirect with HTTP from PHP you do:

header('Location: http://example.com/');
exit();

As mentiond above, you can also use output buffering so that you can have a header() call after you output some HTML or what not.

May I also know how is it solved.
I have the same problem too :(
I copied the same code from my old website.
It's working in the old site. But when I copied it to the new site, it's not redirecting and I have the error message Warning.
Please help.

Thanks,

Thank you Kulinh, you're right! My code is now working....

Thank you...Thank you...Thank you...

Roland

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.