...

View Full Version : Header Problem?



wincode
11-21-2010, 12:05 AM
Hello I'm getting this error:
Warning: Cannot modify header information - headers already sent by (output started at blahblah/pages.php:5) in blahblah/comments.php on line 14

I can't figure out what's going wrong.
This is what I have in pages.php: (I put up to line 14, line 5 is the "<style ..." line)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<style type="text/css">

body{
background: #C6D0F7;
margin: 0 auto;
font-family: verdana;
height: 100%;
font-size: 11px;
}


....



And this is my comments.php page:

<?php
include ('secure.php');
$comment = no_injection($_POST['comment']);
$id = intval($_GET['id']);
if(isset($_COOKIE["username"])){
$userid=$_COOKIE['userid'];
$sql = mysql_query("SELECT * FROM users WHERE id='$userid'");
while($row = mysql_fetch_array($sql)){
$url = 'index.php?pages=profile&id='.$id.'&messages=done#commentmessage';
if ($row['password'] == $_COOKIE['code']) {
mysql_query("INSERT INTO comments (user, comment, profileid) VALUES ('$userid', '$comment', '$id')") or die (mysql_error());
header("Location: $site_url/$url");
}}}
?>


Appreciate any help
Thanks

MattF
11-21-2010, 12:54 AM
You have to issue any headers before you send any page output to the client.

low tech
11-21-2010, 01:15 AM
Hi


headers already sent by


open file pages.php:5
Remove these 3  from yr page just before <?php at top


you will need to use an HEX editor to see them

I use this free one
http://mh-nexus.de/en/hxd/

save (without bom signature)

LT

DrDOS
11-21-2010, 04:19 AM
Or maybe?

}}}
header("Location: ".$site_url."/".$url);
exit();
?>

wincode
11-21-2010, 04:48 AM
@MattF: how do I issue the header if I have a template? The comments.php is an include in pages.php

@Low_Tech: I checked the file with the Hex editor, but I couldn't find  in them

@DrDos: I tried that, and it's not working.

Thanks a lot for your time

aimads
11-21-2010, 07:24 AM
if you use : Notepad ++
change page Encoding to UTF-8 Without BOM.

try this solution.

MattF
11-21-2010, 10:54 AM
Post the complete pages.php file.

wincode
11-21-2010, 04:55 PM
@Aimads: I changed it to UTF-8 Without BOM, saved it, but I still had the same problem. When I closed and reopened the page, it was back to Ansi.

I've uploaded the file to here. (http://www.2shared.com/file/swwOwPzv/pages.html)

Thank you

djm0219
11-21-2010, 05:04 PM
That download is an executable and nobody is going to download it. Post the contents of the page here please (using the proper PHP tags).

wincode
11-21-2010, 05:19 PM
Oh I'm sorry. Here's the content:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<style type="text/css">

body{
background: #C6D0F7;
margin: 0 auto;
font-family: verdana;
height: 100%;
font-size: 11px;
}

html{height: 100%;}

#headerz{
min-width: 1000px;
width: 100%;
background: #bb2448;
height: 100px;
}
#top{width: 1000px;
margin: 0 auto;
}
#topleft{
width: 200px;
float: left;}

#topright{
width: 300px;
float: right;
padding-top: 5px;}


#bars
{
min-width: 1000px;
width: 100%;
background: #333;
height: 35px;
}




/* THE BODY*/

#main{
width: 1000px;
margin: 0 auto;
background: #eee;
border-left: #333 solid 1px;
border-right: #333 solid 1px;
overflow: auto;
}

#bodyleft{
width: 200px;
float: left;
background: #eeeeee;
height: 100%;
}
#bodymid{
width: 650px;
float: left;
background: #eeeeee;
height: 100%;
}
#bodyright{
width: 150px;
float: right;
background: #eeeeee;
height: 100%;
padding-top: 5px;
}


#foot
{
min-width: 1000px;
margin: 0 auto;
width: 100%;
background: #444;
height: 35px;
color: #ccc;
}

#footpadder{
line-height: 35px;
width: 1000px;
margin: 0 auto;
}




/* THE MENU*/
#bar
{
list-style: none;
margin: 0;
}

#topbar
{
width: 1000px;
margin: 0 auto;
}

#bar li
{
list-style: none;
background: #333;
float: left;
line-height: 35px;
}
#bar a
{
color: #ccc;
text-decoration: none;
height: 35px;
padding: 0 25px;
display: block;
}
#bar a:hover
{
color: #fff;
background: #355999;
text-decoration: none;
}


/*The Roundbox*/
.spiffy{display:block}
.spiffy *{
display:block;
height:1px;
overflow:hidden;
font-size:.01em;
background:#eeeeee;
}
.spiffy1{
margin-left:3px;
margin-right:3px;
padding-left:1px;
padding-right:1px;
border-left:1px solid #da6666;
border-right:1px solid #da6666;
}
.spiffy2{
margin-left:1px;
margin-right:1px;
padding-right:1px;
padding-left:1px;
border-left:1px solid #cf1717;
border-right:1px solid #cf1717;
background:#e7c0c0;}
.spiffy3{
margin-left:1px;
margin-right:1px;
border-left:1px solid #e7c0c0;
border-right:1px solid #e7c0c0;}
.spiffy4{
border-left:1px solid #da6666;
border-right:1px solid #da6666}
.spiffy5{
border-left:1px solid #e5b2b2;
border-right:1px solid #e5b2b2;}
.spiffyfg{
background:#eeeeee;
text-align: right;
padding-right: 5px;
padding-left: 5px;
height: 80px;}




#loginboxleft{
width: 80px;
height: 80px;
float: left;
}

#loginboxright{
width: 100%-80px;
height; 80px;
float: right}




#comment{width: 400px; margin: 0 auto; overflow: auto;}
#comment2wrap{float: left; width: 100%;}
#comment2{padding-left: 5px; margin-left: 60px; min-width: 200px; min-height: 70px;}
#comment1{float: left; width: 60px; margin-left: -100%;}
#commenttitle{ font-weight: bold;}

#commentadded{margin: 0 auto; height: 25px; text-align: center; color: #eee; width: 300px; border: 1px solid #008000; background: #239953;}







#twocolmain{width: 750px; margin: 0 auto;min-height: 35px;border-top: 1px #355999 solid;background: #ffffff;}
#twocolmain2{width: 750px; margin: 0 auto;min-height: 35px; max-height:35px;border-top: 1px #355999 solid;background: #eaf2d3;}
#twocolwrap{float: left;width: 100%;}
#twocol2{margin-left: 20%; width: 80%; padding-left: 5px; padding-top: 5px;}
#twocol1{float: left;width: 20%; margin-left: -100%; padding-top: 5px}


#profilecol{width: 100%; margin: 0 auto; margin-top: -5px;}
#profilecol2wrap{float: left; width:100%;}
#profilecol2{margin-left: 200px; width: 575; padding-left: 5px; padding-top: 5px;}
#profilecol1{float: left; margin-left: -100%; width: 200px; padding-top: 5px;}


#subcol{width: 100%; margin: 0 auto; overflow: auto;}
#subcol2wrap{float: left; width: 100%}
#subcol2{margin-left: 50%; width: 50%-5px; padding-left: 5px; }
#subcol1{float: left; margin-left: -100%; width: 50%; }


#halfcol{width: 100%; margin: 0 auto;}
#halfcol2wrap{float: left; width: 100%}
#halfcol2{margin-left: 50%; width: 25%; padding-left: 5px; background: #ffcfcf;}
#halfcol1{float: left; width: 25%; margin-left: -75%; padding-right: 5px; background: #ffcfcf; text-align: right; font-weight: bold;}

#half2col{width: 100%; margin: 0 auto;}
#half2col2wrap{float: left; width: 100%}
#half2col2{margin-left: 50%; width: 25%; padding-left: 5px; background: #dfebf1;}
#half2col1{float: left; width: 25%; margin-left: -75%; padding-right: 5px; background: #dfebf1; text-align: right; font-weight: bold;}



#profileheader{width: 100%; height: 25px; margin: 0 auto;background: #dfebf1; border-top: 1px solid #355999;}
#profilehtext{width: 100%-5px; padding-left: 5px; padding-top: 5px; font-weight: bold;}

#profileque{padding-left: 5px;width: 100%-5px; text-align: left; font-weight: bold; color: #aaa;}
#profileans{padding-left: 10px;}

#profilec{width: 100%; background: #ff0000; overflow: auto;}
#profilec1{width: 70px; background: #ffff00; float: left;}
#profilec2{width: 200px; padding-left: 5px; background: #00ff00; float: left;}
#profilec3{width: 15px; padding-left: 5px; background: #00ffff; float: left;}
#profilec4{width: 160px; padding-left: 5px; background: #0000ff; float: left;}
#profilec5{width: 160px; padding-left: 5px; background: #ff00ff; float: left;}


#padder{
padding: 5px;}
</style>
</head>


<body>
<div id="headerz">
<div id="top">
<div id="topleft">
<img src="logo.png" />
</div>
<div id="topright">
<div>
<b class="spiffy">
<b class="spiffy1"><b></b></b>
<b class="spiffy2"><b></b></b>
<b class="spiffy3"></b>
<b class="spiffy4"></b>
<b class="spiffy5"></b></b>

<div class="spiffyfg">

<?
if(isset($_COOKIE['username']))
{
$uid=$_COOKIE['userid'];
echo'<div id="loginboxleft">';
$profileboximg=mysql_query("SELECT * FROM users where id='$uid'") or die($mysql_error);
$profileboximg2=mysql_fetch_array($profileboximg);
echo'<img src="'.$site_url.'/avatars/thumbs/thumb_'.$profileboximg2['profilepicture'].'" height="80px">
</div>
<div id="loginboxright">';
$uid=$_COOKIE['userid'];
echo$_COOKIE['username'].'<br/>
<a href="index.php?pages=profile&id='.$uid.'">My Profile</a><br/><a href="login.php?action=logout">Logout</a>';
echo'</div>';
}
else{
echo'
<form action="login.php" method="POST">
Email: <input type="text" name="email"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" name="submit" value="Login">
or <a href="index.php?pages=register">Register</a>
</form>';
}
?>

</div>

<b class="spiffy">
<b class="spiffy5"></b>
<b class="spiffy4"></b>
<b class="spiffy3"></b>
<b class="spiffy2"><b></b></b>
<b class="spiffy1"><b></b></b></b>
</div>



</div>

</div>
</div>

<div id="bars">
<div id="topbar">
<ul id="bar">
<li><a href="index.php">Home</a></li>
<li><a href="index.php?pages=profiles">Profiles</a></li>
<li><a href="index.php?pages=videos">Videos</a></li>
<li><a href="index.php?pages=rankings">Rankings</a></li>
</ul>
</div>
</div>


<div id="main">
<div id="bodyleft">
Left Column<br/>
</div>
<div id="bodymid"><div id="padder">
<?php include('content.php'); ?>
</div></div>
<div id="bodyright">
Right column<br/>
</div>
</div>

<div id="foot"><div id="footpadder">
Footer
</div>
</div>

</body>

</html>

DrDOS
11-21-2010, 05:33 PM
That download is an executable and nobody is going to download it. Post the contents of the page here please (using the proper PHP tags).The actual link to the uploaded file is way down at the bottom of the box and hard to see. The big download button is not it! Sneaky people.

djm0219
11-21-2010, 05:35 PM
The actual link to the uploaded file is way down at the bottom of the box and hard to see. The big download button is not it! Sneaky people.

Ah, sneaky indeed.

MattF
11-21-2010, 05:42 PM
The only way you're going to sort it with that script is to use output buffering, unless you practically rewrite the thing. Change the top of the script to:



<?php

ob_start();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">


and at the very end of the script put:



<?php

$output = ob_get_contents();
ob_end_clean();
exit($output);

?>


It's actually a poorly designed script, but you have the easy option, (hack), above or the hard option to sort it. Put an exit() call after the header call in that other script too, as DrDos suggested earlier.

wincode
11-21-2010, 07:25 PM
Matt F: The two codes you provided did the job. :)
But the other way is to sort it out? How would I go about that?

Thanks a lot for all your help

MattF
11-21-2010, 08:35 PM
But the other way is to sort it out? How would I go about that?

I wouldn't worry about it, to be honest. There's nothing wrong with output buffering per se, (I use it myself so that I can do any output alterations necessary and such). It's just a bit more hacky in your case because of the fact that the script isn't exactly written logically, (hence why the problem exists), but it will do no harm whatsoever to leave as is.

wincode
11-22-2010, 12:25 AM
Alright thanks for all the help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum