473,231 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Again "headers already sent by ".

Q
Hello,

I have composed the following simple php file:
<html>
<head><title> Title. </title></head>
<body>
<?php
header("Location: http://www.something.com/tmp2.php");
?>
</body>
</html>

And result of its execution is:
Warning: Cannot modify header information - headers already sent by
(output started at /home/something/public_html/tmp1.php:4) in
/home/something/public_html/tmp1.php on line 5

I thing, that in newsgroups I found a cause of my error:
"The reason you are getting this warning is because PHP is trying to
send a header (redirecting in this case) to browser, but it cannot,
because the output has already started."

But now I do not understand what is the use of header("Location:
***");. It can be placed only in the beginning of files, and after
browser open this file it (browser) is immediatly redirected to second
file. Is it not better to open second file straight away (withou
opening the first file)? Further, what I need to do if I want to
diplay some file and than, let say in 20 second, user have to be
redirected to next file? What I need to do if I want to perform
redirection only if some variables have same defined values?

Pleas help me if you know answers.
Thank you.
Jul 17 '05 #1
4 2268
Q wrote:
Hello,

I have composed the following simple php file:
<html>
<head><title> Title. </title></head>
<body>
<?php
header("Location: http://www.something.com/tmp2.php");
?>
</body>
</html>

And result of its execution is:
Warning: Cannot modify header information - headers already sent by
(output started at /home/something/public_html/tmp1.php:4) in
/home/something/public_html/tmp1.php on line 5

I thing, that in newsgroups I found a cause of my error:
"The reason you are getting this warning is because PHP is trying to
send a header (redirecting in this case) to browser, but it cannot,
because the output has already started."

But now I do not understand what is the use of header("Location:
***");. It can be placed only in the beginning of files, and after
browser open this file it (browser) is immediatly redirected to second
file. Is it not better to open second file straight away (withou
opening the first file)? Further, what I need to do if I want to
diplay some file and than, let say in 20 second, user have to be
redirected to next file? What I need to do if I want to perform
redirection only if some variables have same defined values?

Pleas help me if you know answers.
Thank you.


You have already created an html page with the tags, that is the output.
The headers, sent with header(), can only arrive BEFORE any other output
in the file.

What I think u are trying to do, is include html tags and php code from
tmp2.php into tmp.php.
If this is the case, try include(<your page>); in stead of header().

HTH

Stijn
Jul 17 '05 #2
Q wrote:
Hello,

I have composed the following simple php file:
<html>
<head><title> Title. </title></head>
<body>
<?php
header("Location: http://www.something.com/tmp2.php");
?>
</body>
</html>

And result of its execution is:
Warning: Cannot modify header information - headers already sent by
(output started at /home/something/public_html/tmp1.php:4) in
/home/something/public_html/tmp1.php on line 5
Which makes sense.
You did produce output already.

Do not confuse headers with meta-tags or something like that.
You produced output because you printed: <html><head> etc etc..


I thing, that in newsgroups I found a cause of my error:
"The reason you are getting this warning is because PHP is trying to
send a header (redirecting in this case) to browser, but it cannot,
because the output has already started."
Sounds correct.

But now I do not understand what is the use of header("Location:
***");.
lemmie help you then. :-)
It can be placed only in the beginning of files, and after
browser open this file it (browser) is immediatly redirected to second
file.
correct, but don't use the word 'file'.
It is just a resource or better: URL or URI, not always a simple file.

Is it not better to open second file straight away (withou
opening the first file)?
If that doesn't break anything, well... of course!
Why send somewhere without reason?

COnsider the following situation:

page1.php contains a nice page with a form. The action of the form is
page2.php

page2.php contains logic to receive the form and insert some records in some
database.

Ok?

The problem you face now is that a client fills in the form on page1.php and
presses submit, the data in the form is send to page2.php.
page2.php processes this information and inserts it into the database.

......

And now?

Do you want to let your visitor see an empty page, since page2.php finished
its job and didn't produce any output/html.

So here is a situation where you would like to use a header("Location:
page1.php");

Then the clients browser receives a command to go to page1.php

Does it make sense now?
Further, what I need to do if I want to
diplay some file and than, let say in 20 second, user have to be
redirected to next file? What I need to do if I want to perform
redirection only if some variables have same defined values?
Use javascript or META-tags, not PHP.

In javascript: use window.setTimeout("location='anotherpahe.html';" , 500);

google for the metatag, i never use it, so don't know the syntax.

Pleas help me if you know answers.
Thank you.

You are welcome.
Regards,
Erwin Moller
Jul 17 '05 #3
I noticed that Message-ID:
<5f**************************@posting.google.com > from Q contained the
following:
But now I do not understand what is the use of header("Location:
***");. It can be placed only in the beginning of files, and after
browser open this file it (browser) is immediatly redirected to second
file. Is it not better to open second file straight away (withou
opening the first file)?
Let's say you have a series of pages where you require the user to log
in. You store the log in status as a session variable and then check
for its existence at the start of each page, before any HTML. If it
doesn't exist you can redirect the user to the login page via the header
function.
Further, what I need to do if I want to
diplay some file and than, let say in 20 second, user have to be
redirected to next file? Once the PHP process is over the server has no knowledge of what is
going on at the client side. To redirect in 20 seconds requires a
client side process, ie JavaScript or meta refresh
What I need to do if I want to perform
redirection only if some variables have same defined values?


Put all the PHP code before any html. <?php must be absolutely the first
thing on your page.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
I noticed that Message-ID: <42***********************@news.xs4all.nl>
from Erwin Moller contained the following:
google for the metatag, i never use it, so don't know the syntax.


<meta http-equiv="refresh" content="20;URL=http://www.example.com">
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Donovan Martin | last post by:
Detecting dead headers is an extremely tiresome and lengthy process. Is there an automated utility available which might do this for me? That is, some utility that will check my .cpp and .h files...
2
by: Gianni Mariani | last post by:
I'm getting "multiply defined" errors on STL symbols. Isn't this a linker error ? By definition, doesn't the compiler/linker need to guarentee the "one definition rule". Linking... ...
1
by: Tom Wild | last post by:
Hi I am trying to create a webform that connects to an Access database. If I use the connection string: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Gizmo\Gizmo.mdb" Then the application...
2
by: JohnB | last post by:
hi I am using System.Web.Mail.MailMessage to send email. Is there any way to keep the email to "Sent Items" Folder?? I use Microsoft Outlook as my email tool. Thanks
6
by: Grumpy Aero Guy | last post by:
I would like to add functionality to a form that contains a check box with which the end user can check it so that this particular form won't appear again. I. e., a "Don't show this form again"...
2
by: monomaniac21 | last post by:
Hi all! How can i get round this. I want to stick an include at the top of my script for the connection to DB and then somewhere below this process a form and if all is good execute a redirect...
7
by: seven.reeds | last post by:
Hi, I have a caontainer div that is 80% of the width of my display and 40em high. It will hold from 2 to 10 columns of data and will almost always have more than 40ems of lines... so it will...
0
by: miha.valencic | last post by:
Is there a way (int ASP.NET 1.1 or 2.0) to check which "Cache-Control" headers have been output or set before the page is written to output stream? There is Response.Headers property in .NET...
1
by: dwasler | last post by:
Try every thing I know to remove this alias I know there been other posting I read each one none seem to work. Thank You DLWasler dwasler@yahoo.com OS Window db2 V 8.2.X
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.