Powered by:
FutureQuest Hosting


"...Remember being a youngster, mom or dad telling you "close the door"? Well the same applies to HTML ...."

Web Hosting
Shared       
Reseller     
VPS             
Dedicated 
Price:   $(US)
Space:     (MB)
Transfer:(GB)
Platform:


Advertise
Advertising Opportunities
Rate Card

Sponsor
Go Back   Webmaster Forums > Code Forum > PHP Forum


Reply
 
Thread Tools Rate this Webmaster Discussion
  #1  
Old 05-24-2009, 07:55 AM
zzz zzz is offline
Junior Member
 
Join Date: Jan 2009
Webmaster Discussions: 5
Rep Power: 6
zzz is on a distinguished road
Warning: Cannot modify header information - headers already sent by (output started a

hi,
can anybody help me i this regards.
problem is as follows

i have a form .
here i am getting a value through a file.
based on the value i decide the header.but before that i pass a meta data also.

<html>
<meta http-equiv="refresh" content="2;url=http://localhost/cba.php" />
<?php
$handle=fopen('c:/aaa.txt','r');
$a=fgets($handle);
fclose($handle);
if($a!=0)
header( 'refresh: 5; url=http://localhost/abc.php' );
else
header( 'refresh: 5; url=http://localhost/cba.php' );
?>
</html>

so here once i do this a warning will come up saying
"Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\abc.php:7) in C:\Program Files\Apache Group\Apache2\htdocs\abc.php on line 462
"

so can anyone give me solution for this.pls


Reply With Quote
  #2  
Old 05-29-2009, 01:46 PM
jthayne's Avatar
jthayne jthayne is offline
Senior Member
 
Join Date: Aug 2008
Location: Texas
Webmaster Discussions: 487
Rep Power: 15
jthayne is the hardest working person in the biz. jthayne is the hardest working person in the biz. jthayne is the hardest working person in the biz. jthayne is the hardest working person in the biz.
Re: Warning: Cannot modify header information - headers already sent by (output start

Sorry about the delayed response. I have been gone for a little while, but I am back now.

When using the header() function in PHP, there can be nothing output to the screen before the function is called. Any HTML is considered output to the screen. What you need to do is move your PHP code to before the HTML as follows:

PHP Code:
<?php
$handle
=fopen('c:/aaa.txt','r');
$a=fgets($handle);
fclose($handle);
if(
$a!=0)
header'refresh: 5; url=http://localhost/abc.php' );
else
header'refresh: 5; url=http://localhost/cba.php' );
?>
<html>
<meta http-equiv="refresh" content="2;url=http://localhost/cba.php" />
</html>
Viola! No more error.
__________________
Be sure to click the reputation icon to give rep to the person who helped you.
Check out the following sites: www.inbutnotoftheworld.com and www.mythoughtexactly.com.

Last edited by jthayne; 05-29-2009 at 01:53 PM.
Reply With Quote
  #3  
Old 08-26-2009, 01:19 AM
markei markei is offline
Junior Member
 
Join Date: Mar 2009
Location: Westminster, MD
Webmaster Discussions: 14
Rep Power: 6
markei has a spectacular aura about markei has a spectacular aura about
Wink Re: Warning: Cannot modify header information - headers already sent by (output start

Viola? Why not Bass Fiddle?
__________________
Keep In Tune!
markei
Reply With Quote
  #4  
Old 11-02-2009, 03:44 AM
kaly kaly is offline
Junior Member
 
Join Date: Nov 2009
Webmaster Discussions: 1
Rep Power: 1
kaly is on a distinguished road
Re: Warning: Cannot modify header information - headers already sent by (output start

hi,
i m getting the same "Cannot modify header information - headers already sent in .. " error. There's no white space b4 or after php tags. Here is my code-

<? ob_start(); ?>
<?php
session_start();
if(isset($_POST['login']))
{
if(!$fh = fopen('pwd.dat','w')) {
do_error_exit('Error opening data file. <br />Please contact the system administrator. <br />Sorry for the inconvenience.');
}

$username1[0]= 'kaly';
$username1[1]= crypt('mypassword','rl');

$user_pass_string= implode('=',$username1);
fwrite($fh,"$user_pass_string\n");

flock($fh);
flush($fh);
fclose($fh);

$username = $_POST['username'];
$password = $_POST['pswd'];

$tempwd = crypt($password,'rl');

$fh = fopen('pwd.dat','r');

for($line = fgets($fh); !feof($fh) ; $line = fgets($fh))
{
$line = trim($line);
$userData = explode("=",$line);
if ($userData[0] == $username)
$pass = $userData[1];

}
fclose($fh);
if (crypt($password, $pass) == $pass){
$_SESSION['phplogin'] = true;
header('Location: index.php');
exit;
} else {
?>
<script type="text/javascript">
<!--
alert('Wrong Password, Please Try Again')
//-->
</script>
<?php
}
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> PHP Login </title>
</head>
<body>
<center>
Username:<br>
Password:<br>
<form method="post" action="">
<input type="username" name="username">
<input type="password" name="pswd">
<input type="submit" name="login" value="Login">
</form>
</center>
</body>
</html>
<? ob_flush(); ?>
Reply With Quote
  #5  
Old 11-02-2009, 01:23 PM
sac0o01's Avatar
sac0o01 sac0o01 is offline
Junior Member
 
Join Date: Nov 2009
Location: USA
Webmaster Discussions: 1
Rep Power: 1
sac0o01 is on a distinguished road
Re: Warning: Cannot modify header information - headers already sent by (output start

I would say Short Tags are not enabled on your host. You can change it in your php.ini file but it is easiest to fix the code.

Change:
PHP Code:
<? ob_start(); ?>
To:
PHP Code:
<?php ob_start(); ?>
Remember to change the line at the bottom as well.
Reply With Quote
  #6  
Old 11-04-2009, 10:11 AM
jthayne's Avatar
jthayne jthayne is offline
Senior Member
 
Join Date: Aug 2008
Location: Texas
Webmaster Discussions: 487
Rep Power: 15
jthayne is the hardest working person in the biz. jthayne is the hardest working person in the biz. jthayne is the hardest working person in the biz. jthayne is the hardest working person in the biz.
Re: Warning: Cannot modify header information - headers already sent by (output start

Actually what needs to happen, is you need to move
PHP Code:
<? ob_start(); ?>
to just before you actually have output you are buffering as this function opens the output buffer which is where your problem lies.

My recommendation is to move it just before this line:
HTML Code:
<script type="text/javascript">
__________________
Be sure to click the reputation icon to give rep to the person who helped you.
Check out the following sites: www.inbutnotoftheworld.com and www.mythoughtexactly.com.
Reply With Quote
Reply
Sponsor

Bookmarks

Tags
header , modify

Thread Tools
Rate This Thread
Rate This Thread:

 

Similar Webmaster Discussions
Thread Webmaster Discussion Starter Forum Replies Last Post
mypsace modify friends help? ineedhelpmyspace Myspace Forum 0 06-19-2009 01:17 PM
Premature end of script headers error madan9999 CGI Perl Forum 1 08-16-2006 03:16 PM
Question about Headers (I think) sshadow HTML Forum 5 04-10-2001 03:48 PM


All times are GMT -5. The time now is 04:47 PM.

Copyright © 1999 - 2009 Advanced HTML For Beginners and AHFB2000. All rights reserved.
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.