View Full Version : Getting a header error
DigitalBliss
03-29-2005, 07:55 PM
Hey when I try to make this script write a cookie I get this error
Warning: Cannot modify header information - headers already sent by (output started at c:\appserv\www\mypicx\layout.php:140) in c:\appserv\www\mypicx\account.php on line 64
account.php line 56 - 72
$mp_username = $row['username']; $mp_password = $row['password']; $mp_email = $row['email']; $mp_image = $row['image']; $mp_name = $row['name']; $mp_city = $row['city']; $mp_state = $row['state']; $mp_country = $row['country']; $mp_aim = $row['aim']; $mp_icq = $row['icq']; $mp_yahoo = $row['yahoo']; $mp_msn = $row['msn']; $mp_sex = $row['sex']; $mp_mm = $row['mm']; $mp_dd = $row['dd']; $mp_yyyy = $row['yyyy']; $mp_bio = $row['bio']; $mp_turnons = $row['turnons']; $mp_turnoffs = $row['turnoffs']; $mp_registered = $row['registered']; $mp_lastlogin = $row['lastlogin']; $mp_ip = $row['ip']; $mp_active = $row['active'];
// Database Coding //
$md5pass = md5($password);
if($md5pass == $mp_password){
$loginduration = "60";
$usercookie = base64_encode("$username||$md5pass");
setcookie("mypicxuser","$usercookie", time() + $loginduration);
tablehead(1, "Login Successfull");
echo"Login Successfull";
tablefoot(1);
}else{
tablehead(1, "Login Failed");
echo"**** off *****";
tablefoot(1);
}
Line 64, where it says the problem is is this
setcookie("mypicxuser","$usercookie", time() + $loginduration);
Someone please help. Thanks for any replies.
devinemke
03-29-2005, 07:58 PM
read up on headers (http://www.phpbuilder.com/board/showthread.php?s=&postid=10453971#post10453971)
Fou-Lu
03-29-2005, 08:00 PM
Lol, thats not very informative, just like a 500 error :p
You have that problem because you have sent output to your browser. Two ways to fix this without massively overhauling your code is to look into using external templates, or look into using output buffering (http://ca3.php.net/manual/en/ref.outcontrol.php).
Hope that helps!
devinemke
03-29-2005, 08:08 PM
Lol, thats not very informative, just like a 500 error
well actually, the link i provided explains very specifically what would cause the error that DigitalBliss mentioned...but if that's considered not very informative, so be it.
DigitalBliss
03-29-2005, 08:11 PM
hey devinemke do you have any messengers?
Fou-Lu
03-29-2005, 08:12 PM
No, the link was fine.
I'm just making the point of quickly telling him why the error is there, and the easiest ways to solve it. Don't get me wrong, I quite enjoyed the article, but we shouldn't assume that people have a strong knowledge of HTTP requests/responses and how to use header functions. Thats all I was getting at.
As well, I originally thought that your link was for the php resource on headers, which I know is pretty much useless for this :P
DigitalBliss
03-29-2005, 08:15 PM
lol i looked at both the sites and it just got me more lost in all of this. I need some serious help :(
Fou-Lu
03-29-2005, 08:19 PM
Eh... I think its simply as easy as adding your ob_start() and flush. Been awhile since I've needed to use the output buffering.
<?php
ob_start();
// Bunch 'o code.
ob_end_flush();
?>
Don't *think* you need to worry about getting your contents on this.
DigitalBliss
03-29-2005, 08:27 PM
Do I put those functions around the whole php file or only around the login function?
We need to see the code in c:appservwwwmypicxlayout.php to judge this i guess.
DigitalBliss
03-29-2005, 09:05 PM
That is my layout coding lol well here it is:
layout.php
<?php
function pageheader(){
echo"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
. "<http://www.w3.org/TR/html4/loose.dtd\">"
. "<html>"
. "<head>"
. "<title>MyPicx :: Share Your Pic Online</title>"
. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
. "<link href=\"style/main.css\" rel=\"stylesheet\" type=\"text/css\">"
. "<link REL=\"shortcut icon\" HREF=\"images/favicon.ico\" TYPE=\"image/x-icon\">"
. "<script src=\"js/rollover.js\" type=\"text/javascript\"></script>"
. "<script src=\"js/overlib.js\" type=\"text/javascript\"></script>"
. "</head>";
themeheader();
}
function pagefooter(){
themefooter();
}
function themeheader(){
function search(){
echo"<form name=\"search\" action=\"search.php\" method=\"post\">"
."<div align=\"right\"><b>Username</b> "
."<input class=\"textfield\" type=\"text\" name=\"keyword\" maxlength=\"15\" size=\"25\"> "
."<input type=\"hidden\" name=\"function\" value=\"search\">"
."<input class=\"submit\" type=\"submit\" value=\"Search\"></form></div>";
}
echo"<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">"
. "<center>"
. "<table id=\"Table_01\" width=\"90%\" height=\"80\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
. "<tr>"
. " <td rowspan=\"3\">"
. " <img src=\"images/head/layout-hd_01.gif\" width=\"309\" height=\"80\" alt=\"\"></td>"
. " <td rowspan=\"3\" background=\"images/head/layout-hd_02.gif\" width=\"100%\" height=\"80\" alt=\"\"></td>"
. " <td colspan=\"6\">"
. " <img src=\"images/head/layout-hd_03.gif\" width=\"445\" height=\"34\" alt=\"\"></td>"
. "</tr>"
. "<tr>"
. " <td>"
. "<a href=\"index.php\"><img src=\"images/head/layout-hd_04.gif\" width=\"88\" height=\"20\" alt=\"\" class=\"imgover\" border=\"0\"></a></td>"
. " <td>"
. "<a href=\"rate.php\"><img src=\"images/head/layout-hd_05.gif\" width=\"88\" height=\"20\" alt=\"\" class=\"imgover\" border=\"0\"></a></td>"
. " <td>"
. "<a href=\"search.php\"><img src=\"images/head/layout-hd_06.gif\" width=\"88\" height=\"20\" alt=\"\" class=\"imgover\" border=\"0\"></a></td>"
. " <td>"
. "<a href=\"pm.php\"><img src=\"images/head/layout-hd_07.gif\" width=\"88\" height=\"20\" alt=\"\" class=\"imgover\" border=\"0\"></a></td>"
. " <td>"
. "<a href=\"account.php\"><img src=\"images/head/layout-hd_08.gif\" width=\"88\" height=\"20\" alt=\"\" class=\"imgover\" border=\"0\"></a></td>"
. " <td>"
. "<img src=\"images/head/layout-hd_09.gif\" width=\"5\" height=\"20\" alt=\"\" class=\"imgover\" border=\"0\"></a></td>"
. "</tr>"
. "<tr>"
. " <td colspan=\"6\" background=\"images/head/layout-hd_10.gif\" width=\"445\" height=\"26\" alt=\"\">";
echo"</td>"
. "</tr>"
. "</table>"
. "<table id=\"Table_01\" width=\"90%\" height=\"20\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
. "<tr>"
. "<td background=\"images/layout-lside.gif\" width=\"10\">"
. "<img src=\"images/layout-lside.gif\" width=\"10\">"
. "</td>"
. "<td width=\"100%\" bgcolor=\"#FFFFFF\">";
echo"<table width=\"100%\">"
."<td><b>Welcome, Anonymous</b></td>"
."<td>";
search();
echo"</td></table>";
announcement(0);
}
function themefooter(){
echo"<td background=\"images/layout-rside.gif\" width=\"10\">"
. "<img src=\"images/layout-rside.gif\" width=\"10\">"
. "</td>"
. "</tr>"
. "</table>"
. "<table id=\"Table_01\" width=\"90%\" height=\"40\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
. "<tr>"
. " <td colspan=\"6\">"
. " <img src=\"images/foot/layout-ft_01.gif\" width=\"202\" height=\"28\" alt=\"\"></td>"
. " <td rowspan=\"3\" background=\"images/foot/layout-ft_02.gif\" width=\"100%\" height=\"40\" alt=\"\"></td>"
. " <td rowspan=\"3\">"
. " <img src=\"images/foot/layout-ft_03.gif\" width=\"552\" height=\"40\" alt=\"\"></td>"
. "</tr>"
. "<tr>"
. " <td rowspan=\"2\">"
. " <img src=\"images/foot/layout-ft_04.gif\" width=\"5\" height=\"12\" alt=\"\"></td>"
. " <td>"
. "<a href=\"message.php?function=privacy\"><img src=\"images/foot/layout-ft_05.gif\" width=\"67\" height=\"7\" alt=\"\" border=\"0\"></a></td>"
. " <td rowspan=\"2\">"
. " <img src=\"images/foot/layout-ft_06.gif\" width=\"13\" height=\"12\" alt=\"\"></td>"
. " <td>"
. "<a href=\"message.php?function=tos\"><img src=\"images/foot/layout-ft_07.gif\" width=\"57\" height=\"7\" alt=\"\" border=\"0\"></a></td>"
. " <td rowspan=\"2\">"
. " <img src=\"images/foot/layout-ft_08.gif\" width=\"13\" height=\"12\" alt=\"\"></td>"
. " <td>"
. "<a href=\"contact.php\"><img src=\"images/foot/layout-ft_09.gif\" width=\"47\" height=\"7\" alt=\"\" border=\"0\"></a></td>"
. "</tr>"
. "<tr>"
. " <td>"
. " <img src=\"images/foot/layout-ft_10.gif\" width=\"67\" height=\"5\" alt=\"\"></td>"
. " <td>"
. " <img src=\"images/foot/layout-ft_11.gif\" width=\"57\" height=\"5\" alt=\"\"></td>"
. " <td>"
. " <img src=\"images/foot/layout-ft_12.gif\" width=\"47\" height=\"5\" alt=\"\"></td>"
. "</tr>"
. "</table>"
. "</center>";
echo"<br><center><table width=\"60%\">"
."<td><img src=\"images/logo_sm.gif\"></td>"
."<td><a href=\"sitemap.php\" onmouseover=\"return overlib('Links to pages on this site.', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\">Site Map</a> | <a href=\"message.php?fuction=privacy\" onmouseover=\"return overlib('Read about your privacy on this site.', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\">Privacy & Security</a> |<a href=\"message.php?fuction=tos\" onmouseover=\"return overlib('Terms of use that all users must agree to in using this site.', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\">Terms of Use</a> | <a href=\"contact.php\" onmouseover=\"return overlib('Contact us using an online form.', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\">Contact Us</a> | <a href=\"feedback.php\" onmouseover=\"return overlib('Send us feedback on the site.', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\">Send Feedback</a> | <a href=\"javascript:void(0);\" onmouseover=\"return overlib('Connected Through:<br>Studio Server 5 - VALUDSONY658840', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\">Connection</a><br><br>©2005 MyPicx. All rights reserved.<br>Use of this website signifies your agreement to the <a href=\"message.php?fuction=tos\">Terms of Use</a>.<br>";
visitordetails(1,1,1);
echo"</td></table></center>";
}
function tablehead($break, $tbtitle){
if($break == "1"){
echo"<br>";
}
echo"<table width=\"$tbwidth%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"
. " <tr>"
. " <td><img name=\"table/layout-tb_TL\" src=\"images/table/layout-tb_TL.gif\" width=\"5\" height=\"30\" border=\"0\" alt=\"\"></td>"
. " <td width=\"100%\" background=\"images/table/layout-tb_TM.gif\"><img name=\"table/layout-tb_TM\" src=\"images/spacer.gif\" width=\"5\" height=\"1\" border=\"0\" alt=\"\"><font class=\"tbtitle\">$tbtitle</font></td>"
. " <td><img name=\"table/layout-tb_TR\" src=\"images/table/layout-tb_TR.gif\" width=\"5\" height=\"30\" border=\"0\" alt=\"\"></td>"
. " </tr>"
. " <tr>"
. " <td background=\"images/table/layout-tb_LS.gif\"><img name=\"table/layout-tb_LS\" src=\"images/spacer.gif\" width=\"5\" height=\"1\" border=\"0\" alt=\"\"></td>"
. " <td valign=\"top\" bgcolor=\"#FFFFFF\">";
}
function tablefoot($break){
echo"</td>"
. " <td background=\"images/table/layout-tb_RS.gif\"><img name=\"table/layout-tb_RS\" src=\"images/spacer.gif\" width=\"5\" height=\"1\" border=\"0\" alt=\"\"></td>"
. " </tr>"
. " <tr>"
. " <td><img name=\"table/layout-tb_BL\" src=\"images/table/layout-tb_BL.gif\" width=\"5\" height=\"30\" border=\"0\" alt=\"\"></td>"
. " <td width=\"100%\" background=\"images/table/layout-tb_BM.gif\"><img name=\"table/layout-tb_BM\" src=\"images/spacer.gif\" width=\"5\" height=\"1\" border=\"0\" alt=\"\"></td>"
. " <td><img name=\"table/layout-tb_BR\" src=\"images/table/layout-tb_BR.gif\" width=\"5\" height=\"30\" border=\"0\" alt=\"\"></td>"
. " </tr></table>";
if($break == "1"){
echo"<br>";
}
}
function navhead(){
dbconnect();
$result = mysql_query("SELECT * FROM mpx_members ORDER BY id DESC") or die(mysql_error());
$row = mysql_fetch_array( $result );
$mp_username = $row['username']; $mp_password = $row['password']; $mp_email = $row['email']; $mp_image = $row['image']; $mp_name = $row['name']; $mp_city = $row['city']; $mp_state = $row['state']; $mp_country = $row['country']; $mp_aim = $row['aim']; $mp_icq = $row['icq']; $mp_yahoo = $row['yahoo']; $mp_msn = $row['msn']; $mp_sex = $row['sex']; $mp_mm = $row['mm']; $mp_dd = $row['dd']; $mp_yyyy = $row['yyyy']; $mp_bio = $row['bio']; $mp_turnons = $row['turnons']; $mp_turnoffs = $row['turnoffs']; $mp_registered = $row['registered']; $mp_lastlogin = $row['lastlogin']; $mp_ip = $row['ip']; $mp_active = $row['active'];
$birthday = "$mp_yyyy-$mp_mm-$mp_dd";
$seconds = time() - strtotime($birthday);
$sinyear = "31556926";
$age = $seconds / $sinyear;
$mp_age = floor($age);
$mp_link = "profile.php?username=$mp_username";
$mp_info = "<b>$mp_username</b><br>$mp_age $mp_sex<br>$mp_city, $mp_state";
echo"<table width=\"100%\"><td width=\"20%\" valign=\"top\">";
tablehead(1, "Newest Member");
echo"<fieldset class=\"fieldset\" style=\"margin:10px 0px 0px 0px\">"
."<legend>$mp_username</legend>"
."<center><a href=\"$mp_link\" onmouseover=\"return overlib('$mp_info', FGCOLOR, '#FFFFFF', BGCOLOR, '#CCCCCC', TEXTCOLOR, '#000000');\" onmouseout=\"return nd();\" class=\"foot\"><img src=\"$mp_image\" height=\"100\" width=\"100\" border=\"0\"></a></center>"
."</fieldset>";
tablefoot(1);
tablehead(1, "Top Rated Members");
echo"<fieldset class=\"fieldset\" style=\"margin:10px 0px 0px 0px\">"
."<legend>Guys</legend>"
."- <a href=\"#\">Name1</a> 9.86<br>"
."- <a href=\"#\">Name2</a> 9.85<br>"
."- <a href=\"#\">Name3</a> 9.85<br>"
."- <a href=\"#\">Name4</a> 9.82<br>"
."- <a href=\"#\">Name5</a> 9.80"
."</fieldset>"
."<fieldset class=\"fieldset\" style=\"margin:10px 0px 0px 0px\">"
."<legend>Girls</legend>"
."- <a href=\"#\">Name1</a> 9.92<br>"
."- <a href=\"#\">Name2</a> 9.86<br>"
."- <a href=\"#\">Name3</a> 9.81<br>"
."- <a href=\"#\">Name4</a> 9.80<br>"
."- <a href=\"#\">Name5</a> 9.71"
."</fieldset>";
tablefoot(1);
tablehead(1, "Rate Members");
echo"<fieldset class=\"fieldset\" style=\"margin:10px 0px 0px 0px\">"
."<legend>New Members</legend>"
."- <a href=\"rate.php?sex=m\">Guys</a><br>"
."- <a href=\"rate.php?sex=f\">Girls</a>"
."</fieldset>";
tablefoot(1);
echo"</td><td width=\"80%\" valign=\"top\">";
}
function navfoot(){
echo"</td></table>";
}
?>
Hard to see from the posted code, but is there ANY whitespace or newline in the last file be4 the <?php or after the closing ?> ??
Don't know if u use a hex editor enabled text-editor, but I use ultraedit, which has hexmode. I once encountered strange (non-visible) signs right at the start of a file, which caused the same error. I coulndt even see the signs untill i opened the file in HEX mode. On that occasion, the problem was the file being UTF-8 type. Later changed it to DOS type and the error was gone.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.