php – Cannot modify header information – headers already sent by (php header already sent error)
This error comes when you print any thing before php hreader command
Example Error Code:
<?php
print “text”;
header(‘Location: http://www.example.com/’);
?>
Solution :
<?php
function FunJavaScriptRedirection($url)
{?>
<script type=”text/javascript”>
<!–
window.location = “<?=$url?>”
//–>
</script>
<?}
print “test”;
FunJavaScriptRedirection(“http://www.example.com/”);
?>
gentowa said
Thanks! That’s what I needed for my redirection script now 🙂
digitalpbk said
This is not the recommended method of doing redirections!
See http://digitalpbk.com/php/warning-cannot-modify-header-information-headers-already-sent to understand the error and fix it.
Tharindu Dasun said
WoW dude, Thanks a Lot; This Information is Really Helpfull to me..
to'wan said
thanks mate… i spent whole my time figuring this out.. u rock!!!
Ramesh said
Hi Great,
Thank you so much.
francis said
nice..thanks dude..that was very helpful..
Wasim said
I have used your example. But this page is not re-directed to desired page. Why is this problem occured? Can you help me pls?
A.C.E said
change your code to this:
window.location = “”;
Zzzy said
IT WAS KILLING ME!!!!
Thanks man!!
rupesh said
I just say want to say Thanks.
I was facing this for the error, and urs idea work.
rupesh said
i just want to say many many thanks to u for this advice.
karuppasamy said
Very nice.
niz said
Hi, i’ve used your solution, but the redirect page was’nt display..
pls help me…
niz said
ok…sorry..i forget something…
thanks for your coding…
really help…
Vishal said
this problem have a lot of pages in my site.
Vaasu said
Thanks for solution. but i need solve the php problem. im not ready to go js. please give solution (about header) in php.
thanks………
Mohamad A said
You rock dude. Thanks
am3n said
even a blank line space could generate the error 😀
Amjith PS said
I just say want to say Thanks.
I was facing this for the error, and urs idea work.
myboo said
thnks a lot… its a simple solution, but is very usefull …
thanks …
marxguru said
thanks for ur idea yaar
Kamil said
It´s working! I have to say just thank you men!With headers i had big problem.
I´m form chcech republic and on ours web pages there aren´t good anual howto do that.
IntetkenCer said
There are 5 houses in five different colors
In each house lives a different nationality.
These 5 owners drink a certain beverage, smoke a certain brand of cigar and keep a certain pet.
No owners have the same pet, smoke the same brand of cigar, or drink the same beverage.
The CLUES:
The Brit lives in the Red house.
The Swede keeps dogs as pets.
The Dane Drinks tea.
The Green House is on the left of the White House.
The Green House’s owner drinks coffee.
The person who smokes Pall Mall rears birds.
The owner of the yellow house smokes Dunhill.
The man in the center house drinks milk.
The Norwegian lives in the first house.
The man who smokes Blends lives next to the one who keeps cats
The man who keeps horses lives next to the man who smokes Dunhill.
The man who smokes Blue Master drinks beer.
The German smokes Prince.
The Norwegian lives next to the Blue House.
The man who smokes Blends has a neighbor who drinks water.
The QUESTION:
Who owns the fish?
Akhil said
Thanx a lot. My project survives b’coz of u.
jhili said
thank u so much for responding.It was killing me
syeda said
Thanks u very very mauch ….. i was trying to figure it out for an hour ……
jb.jigar said
Thanks …
Jaswant Kumar Tak said
Its the same like you can use
echo “document.location.href=’new_url.php’
nordage said
Thanks! Very interesting solution.
Adsense Click value said
Thx article useful
MyDigitalZone » Blog Archive » Warning: Cannot modify header information - headers already sent said
[…] Then, you need to check to see if you are using header() before any output is sent. For example, the php.net gives some examples. Here’s another example. […]
maheshchari said
You have done simply better.
but i have one issue,if user disables javascript what you do?
Roe Lee said
You are clever !
But i agree with maheshchari has said, how can we use it when user disabled javascript ?
Srihari said
thanks a lot buddy
Michael Montgomery said
Hi Guy’s,
I know this example originally posted makes sense, but did not work for me. My only solution was to use the meta Refresh…. Major hack but solved my issue.
User1 said
From the above example , i got solution of my requirement. But Can plz tell me how to use following header information
Content-type:
Content-Length:
“Content-Disposition:
Accept-Ranges:
milind said
Thaks, It is very use full
This error is occurs when we write echo “” befire header(“dddddd”);
Rodrigo Machado said
Hey thanks a lot!
noman said
Above code is enogh to page redirect. Some code is not working on firefox mozilla.
So, other option is internet explore. Every time it should be work and it is working.
A programmer should not be copy the code from the internet.
Brian said
This NOT a solution to the problem.
It is a workaround which only avoids the problem if the user has js activated.
Manish said
Sir When we Used Session in a Page and used the Session in another Page then Recived a Error that Header already Sent.
sathish said
i am getting the error,header already sent
Denise Carr said
Thank you VERY much, really helpful!
nalla said
Thanks a lot.. that was really coolest solution..
sushil karki said
just use ob_start() in the begining of the page. no need of javascript.
miff said
Use ob_start() at a very top of your script, and after header(…) use ob_end_flush().
Works great, JS is good but when user disable js…
Ruslan said
I got:
Parse error: syntax error, unexpected T_STRING on line:
FunJavaScriptRedirection(“http://www.example.com/”);
Ruslan said
Sorry…
Parse error: syntax error, unexpected ‘:’ on line:
FunJavaScriptRedirection(“http://www.example.com/”);
Dinesh said
Yes Sir, you have helped me to solve out my problem.
Ayesha said
Thanks..
best solution
Sravan said
Thanks a lot for the info .It helped me a lot
muhsin said
i am getting the error:Warning: Cannot modify header information – headers already sent by (output started at /home/goldento/public_html/welcome/logindispatch.php:13) in /home/goldento/public_html/welcome/logindispatch.php on line 50
please help me
ashokansu said
hello muhsin
this problem is not come in localhost….but sometime give the error in server(not all server)
this is called whitespace problem
you use not space
or
use javascript
window.location
PHP Error: Cannot modify header information – headers already sent by… : Jon Wilber said
[…] One way to fix this problem is by using Javascript or some other language to call the redirect. […]
Peter said
Stupit,
what about if the visitor dont support javascipt.
becasue of designers like YOU.. i HAVE TO turn on javascipts
Ye Henry Tian said
Thanks! It works!
harish said
Hi,
iam facing following error,can any one help me please..
Warning: move_uploaded_file(tempresume/test.doc) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/mgbss/public_html/site1/resume2.php on line 44
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpUaHPQ0’ to ‘tempresume/test.doc’ in /home/mgbss/public_html/site1/resume2.php on line 44
Govind said
dear all,
I’m working php Xampp tools 6.0 php into mysql image store and receive the image. Store the image data base successfully but get the database into php file download the file. replay one error msg.
Warning: Cannot modify header information – headers already sent by (output started at J:\xampp\htdocs\xampp\SMS\download.php:14) in J:\xampp\htdocs\xampp\SMS\download.php on line 60
How to run the program dears replay
jigsaw said
This web page is mostly a stroll-by for all the data you needed about this and didn’t know who to ask. Glimpse here, and also you’ll undoubtedly uncover it.
amitmondal said
Nice tutorial….thanks for this post…..
Please visit this link for learn more script.
http://amitmondal.wordpress.com/
digitalpbk said
There are many solutions to this problem, please see
http://http://digitalpbk.com/php/warning-cannot-modify-header-information-headers-already-sent
paulo said
Great!!! Thanks a lot!!!
sabal said
sabal said
need to solve this problem.link is not working
amila said
Great pal… it works perfectly… Thanx a lot.. and lot more…
phpdev said
Thanks! This saved me lots of trouble & time.
vvv said
function js_redirect($url){echo”
document.location.href='”.$url.”‘;
“;}
Naleen said
🙂
Ya, it really helps me. Thanks a lot for your post.
mediafirehunt said
Solution is very simple. dont change anything on your script,
header(“LOCATION:http://www.google.com“);
this will cause error.
Process 1 : Just Paste
error_reporting(0);
at the top of your page it will works fine.
if not work for you use
Process 2. :
paste
ob_start();
at the top of your page.
and paste
ob_end_flush();
at the bottom of your page
[ NB: process two is very usefull if you host your site into siteground ]
Xopmoyen said
pictures blank scrolls,
Mike said
I had been fighting with that for a few days. Thank You
Maaz Ahmed said
Thanks. It was really effected……….
Manoj Nemade said
Thanks……
shakir said
thanks.. its working. outstanding method
gowsik said
Warning: Cannot modify header information – headers already sent by (output started at /home/klna4/public_html/logininter.php:8) in /home/klna4/public_html/logininter.php on line 36
How to solve this warning for this code
<?php
$username1='';
$companyname='';
if(isset($_POST['companyname']))
$companyname=$_POST['companyname'];
if(isset($_POST['username']))
$username1=$_POST['username'];
if(isset($_POST['password']))
$password1=$_POST['password'];
@$conn=mysql_connect("localhost","klna4_login1","loginform1");
@$db=mysql_select_db("klna4_login")or die(mysql_error());
$result=mysql_query("select * from login") or die(mysql_error());
while($row=mysql_fetch_array($result))
{
if($companyname==$row['company'])
{
if($username1==$row['username'])
{
if($password1==$row['password'])
{
if($row['find']=='0')
{
mysql_query("update login set find='1' where username='$username1'and company='$companyname'");
header("Location:bodypage.php?name=$username1,name2=$companyname");
}
else
{
header("Location:login.php");
}
}
if($password1$row[‘password’])
{
header(“Location:login.php”);
}
}
}
}
?>
free downloader redtube said
hi!,I like your writing very a lot! proportion we be in contact extra about your article on AOL? I require an expert on this area to resolve my problem. Maybe that’s you! Looking ahead to look you.
emil boc & elena udrea said
,
Chandima said
Great!!! Once I removed my all printf and print_r site is working smoothly
Muhammad Sajid said
Use ob_start() and ob_flush() to get rid of this problem. Actually this is a warning message and comes if the output buffer already contains any value it may be some garbage, so at the most top of the file use ob_start() and at the end of the file use ob_flush(). Yap no matter if the file contains session_start() at top.
For more detail please read http://www.php.net/manual/en/function.flush.php
wx3xrc4 Redtube Downloader - Guitar Forum DailyGuitar.com said
[…] You should see this time saving url: Redtube […]
Kritika said
Thanx a lot…You are great.
Mera naam joker said
kuch bhi
source said
This is often a fantastic website, would you be interested in working on an interview concerning just how you produced it? If so e-mail myself!
Manish said
Really Really helpful to me. A Lots of thnx Indeed.
Continue said
When someone writes an article he/she maintains the
plan of a user in his/her mind that how
a user can understand it. Thus that’s why this piece of writing is great. Thanks!
brandybra said
The National Oceanic and Atmospheric Administration of the US government has
announced only last September, the global average for the period January to August 2010 is 580F (14.
Although everyone thought that their city or world would cease
to exist, that was not the actuality. Global warming is caused by burning
hydrocarbons and depleting forests, not by the sun.
siswo said
Yes i have script php here :
<?
header("location:index.php?page=download");
…………….
problem :
Warning: Cannot modify header information – headers already sent by (output started at /home/siprofit/public_html/index.php:15) in /home/siprofit/public_html/download.php on line 7
please advice, thanks
Michaael said
I would not recommend this for security admin area as the user could disable javascript.
Stella said
I all the time emailed this website post page to all
my friends, because if like to read it after that my contacts will too.
dinesh said
I wrote this code insite the word press dashboard page panel but I got the error like
Cannot modify header information – headers already sent by (output started at /home/content/44/10911544/html/onwork/dreamart/wp-content/themes/elegant-photography/header.php:15) in /home/content/44/10911544/html/onwork/dreamart/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 17
my code is
…………………………….
[insert_php]
//error_reporting(0);
$name=$password=$code=”;
if(isset($_POST[‘submit’]))
{
$name=$_POST[‘vm_name’];
$password=$_POST[‘vm_password’];
$code=$_POST[‘vm_code’];
if($name==”dinesh” && $password==”dinesh1″)
{
$_SESSION[‘vm_code’]=$code;
header(“Location: http://vmwebs.com/onwork/dreamart/vasumathywedding“);
}
}
[/insert_php]
need help please
floor Air conditioner said
Undeniably take into consideration that which
you stated. Your best justification have also been concerning the net the simplest thing to bear in mind.
I show you, I certainly get irked while people consider concerns
they can plainly don’t know about.
Glen said
Somebody necessarily lend a hand to make
severely posts I would state. This is the 1st time I frequented your site and thus far?
I amazed with the analysis you made to make this kind
of put up incredible. Fantastic task!
"get the facts" said
“get the facts”
“[…]f Hello there! This is kind of off topic but I need some advice from an estab 0f[…]”
"a cool way to improve" said
“a cool way to improve”
“[…]p Thank you for any other magnificent post. Where else could anyone get that zg[…]”
raghu said
retailmetoday
Kamlesh Dave said
Thanks your code is working and script is woriking gooddddd………………
Wiley said
Managers also develop budget estimates for their departments, and keep track of purchases and expenses to make sure they are in line with budget guidelines.
We also ensure that your nursing papers have been
formatted according to the writing style recommended by your instructor.
A nursing education on the internet gives students flexibility and
is much less highly-priced.
Lucienne said
You post interesting posts here. Your website deserves much more visitors.
It can go viral if you give it initial boost, i know
useful service that can help you, simply search in google:
svetsern traffic tips
Venkat said
http://www.web-technology-experts-notes.in/2015/07/how-to-fix-headers-already-sent-error-in-php.html
M183LCGEIO9M M183LCGEIO9M M183LCGEIO9M www.yandex.ru said
SnhN7cBh