joecooper Posted March 2, 2006 Share Posted March 2, 2006 how can i turn off the warning errors, i get them for "headers allready set" but cant find whats wrong, and it works anyway. just need to make it go from it. Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/ Share on other sites More sharing options...
heckenschutze Posted March 2, 2006 Share Posted March 2, 2006 "Headers already sent" means you have sent output to the browser [u][b]before[/b][/u] you have called a function like header() or session_start() ect. Eg you might have a space before your headers are being sent, yes it matters.Don't ignore errors. Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-13677 Share on other sites More sharing options...
joecooper Posted March 2, 2006 Author Share Posted March 2, 2006 does anyone else know how to turn error reporting off? Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-13689 Share on other sites More sharing options...
heckenschutze Posted March 3, 2006 Share Posted March 3, 2006 [!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--][!--sizeo:7--][span style=\"font-size:36pt;line-height:100%\"][!--/sizeo--][!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--][b]Don't ignore errors.[/b][!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--]PHP was nice enough to tell you about the error, FIX IT. Don't turn it off. Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-13851 Share on other sites More sharing options...
kenrbnsn Posted March 3, 2006 Share Posted March 3, 2006 If you are getting "headers already sent" errors, your script is [b]NOT[/b] working correctly. Fixing whatever is causeing the problems will make the errors go away.If you would post your code, we could help you solve the problem.Ken Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-13890 Share on other sites More sharing options...
dheon09 Posted March 8, 2006 Share Posted March 8, 2006 HI,I'm also having problems with "headers" and did all the possible solution to fix it but to no avail...here's the Warning: "Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site90/fst/var/www/html/connect.php:17) in /home/virtual/site90/fst/var/www/html/connect.php on line 23"here's my code:<?php$user = "user";$pass = "pass";$dbase = "localhost"; $uname = $_POST['user'];$upass = $_POST['pass'];$connection = mysql_connect("localhost",$user,$pass)or die ("Error Connecting to DBase");mysql_select_db($dbase,$connection)or die ("Error Connecting to table");$result = mysql_query("SELECT * FROM usertb",$connection)or die ("Error querying DBase");$i = 0;while($result_ar = mysql_fetch_assoc($result)){mysql_close();?> <?phpob_start();if ($upass == $result_ar['upass'] && $uname == $result_ar['uname']){ header("Location: clients/myoxy/index.html");}elseheader("Location: index.html");?><?php$i+=1;}?>can anyone help me fix this...actually this is working on our network..Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15262 Share on other sites More sharing options...
AV1611 Posted March 8, 2006 Share Posted March 8, 2006 Here is my best guess: I don't know where line 17 is, but I assume it is the line that reads:[code]while($result_ar = mysql_fetch_assoc($result)){[/code]the problem is you use this a few lines before it:[code]$result = mysql_query("SELECT * FROM usertb",$connection)or die ("Error querying DBase");[/code]That causes an error because it doesn't know what $result_ar is, so it can't send headers after that point... Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15265 Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=351111:date=Mar 2 2006, 03:21 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 2 2006, 03:21 PM) [snapback]351111[/snapback][/div][div class=\'quotemain\'][!--quotec--]does anyone else know how to turn error reporting off?[/quote]Hecken is right. Thats definately one you should NOT be ignoring. At least not without detecting and logging it. While you don't want your clients to see error messages, you do not want to ignore them completely.Use error_reporting() to supress warning and error messages. Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15269 Share on other sites More sharing options...
dheon09 Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352722:date=Mar 8 2006, 11:20 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 8 2006, 11:20 AM) [snapback]352722[/snapback][/div][div class=\'quotemain\'][!--quotec--]Here is my best guess: I don't know where line 17 is, but I assume it is the line that reads:[code]while($result_ar = mysql_fetch_assoc($result)){[/code]the problem is you use this a few lines before it:[code]$result = mysql_query("SELECT * FROM usertb",$connection)or die ("Error querying DBase");[/code]That causes an error because it doesn't know what $result_ar is, so it can't send headers after that point...[/quote]can you tell me what should i do...i really need to work this out asap....as i've said before the script works on our local netwokThanks Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15278 Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352735:date=Mar 7 2006, 09:50 PM:name=dheon09)--][div class=\'quotetop\']QUOTE(dheon09 @ Mar 7 2006, 09:50 PM) [snapback]352735[/snapback][/div][div class=\'quotemain\'][!--quotec--]can you tell me what should i do...i really need to work this out asap....as i've said before the script works on our local netwokThanks[/quote]That $result_ar is fine. It is being initialized and set to the results of the query. If the query was bad, the die() would have been executed and your script would have halted. Can you show the entire code? And what is being output? There should be output after that warning. Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15281 Share on other sites More sharing options...
dheon09 Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352738:date=Mar 8 2006, 12:00 PM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 8 2006, 12:00 PM) [snapback]352738[/snapback][/div][div class=\'quotemain\'][!--quotec--]That $result_ar is fine. It is being initialized and set to the results of the query. If the query was bad, the die() would have been executed and your script would have halted. Can you show the entire code? And what is being output? There should be output after that warning.[/quote]If you can see the entire code is posted above, also the Warning...after the warning there was no output...i tried setting a worng pass and user for the connection and it did show the die message so I think the query is good...do you need something else? Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15290 Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352747:date=Mar 7 2006, 10:17 PM:name=dheon09)--][div class=\'quotetop\']QUOTE(dheon09 @ Mar 7 2006, 10:17 PM) [snapback]352747[/snapback][/div][div class=\'quotemain\'][!--quotec--]If you can see the entire code is posted above, also the Warning...after the warning there was no output...i tried setting a worng pass and user for the connection and it did show the die message so I think the query is good...do you need something else?[/quote]Ok, when I remove the clutter of the <? ?> tags, you get this:[code]$user = "user";$pass = "pass";$dbase = "localhost";$uname = $_POST['user'];$upass = $_POST['pass'];$connection = mysql_connect("localhost",$user,$pass)or die ("Error Connecting to DBase");mysql_select_db($dbase,$connection)or die ("Error Connecting to table");$result = mysql_query("SELECT * FROM usertb",$connection)or die ("Error querying DBase");$i = 0;while($result_ar = mysql_fetch_assoc($result)){ mysql_close(); ob_start(); if ($upass == $result_ar['upass'] && $uname == $result_ar['uname']) { header("Location: clients/myoxy/index.html"); } else header("Location: index.html"); $i+=1;}[/code]I don't really know why youre using an ob_start() (especially without a ob_flush()) and you are also closing your connection multiple times. I'm not sure of the effect on the ob_start() and multiple header() calls, but there is no way that the results you will get from that are what you are actually looking for.Try something like this:[code]$found = false;while ($result_ar = mysql_fetch_assoc($result)){ if (($upass == $result_ar['upass']) && ($uname == $result_ar['uname'])) { $found = true; break; }}if ($found) { //valid login header("Location: clients/myoxy/index.html"); }else { //invalid login header("Location: index.html");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15296 Share on other sites More sharing options...
dheon09 Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352753:date=Mar 8 2006, 12:27 PM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 8 2006, 12:27 PM) [snapback]352753[/snapback][/div][div class=\'quotemain\'][!--quotec--]Ok, when I remove the clutter of the <? ?> tags, you get this:[code]$user = "user";$pass = "pass";$dbase = "localhost";$uname = $_POST['user'];$upass = $_POST['pass'];$connection = mysql_connect("localhost",$user,$pass)or die ("Error Connecting to DBase");mysql_select_db($dbase,$connection)or die ("Error Connecting to table");$result = mysql_query("SELECT * FROM usertb",$connection)or die ("Error querying DBase");$i = 0;while($result_ar = mysql_fetch_assoc($result)){ mysql_close(); ob_start(); if ($upass == $result_ar['upass'] && $uname == $result_ar['uname']) { header("Location: clients/myoxy/index.html"); } else header("Location: index.html"); $i+=1;}[/code]I don't really know why youre using an ob_start() (especially without a ob_flush()) and you are also closing your connection multiple times. I'm not sure of the effect on the ob_start() and multiple header() calls, but there is no way that the results you will get from that are what you are actually looking for.Try something like this:[code]$found = false;while ($result_ar = mysql_fetch_assoc($result)){ if (($upass == $result_ar['upass']) && ($uname == $result_ar['uname'])) { $found = true; break; }}if ($found) { //valid login header("Location: clients/myoxy/index.html"); }else { //invalid login header("Location: index.html");}[/code][/quote]i tried your code and tested it locally but it keeps me directed to "[b]index.html[/b]" even if i used the correct username/password.... Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15308 Share on other sites More sharing options...
AV1611 Posted March 8, 2006 Share Posted March 8, 2006 Grey, All I stand corrected... I wrote that when I rolled out of bed this morning... Now that I look at it, I was SOOOOO wrong about the $result_ar thing...Ack!Looking at what the code actually does, there are far easier ways to accomplish what you are trying to do with that script...I don't know if a rewrite is an option... Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15574 Share on other sites More sharing options...
dheon09 Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353036:date=Mar 9 2006, 06:12 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 9 2006, 06:12 AM) [snapback]353036[/snapback][/div][div class=\'quotemain\'][!--quotec--]Grey, All I stand corrected... I wrote that when I rolled out of bed this morning... Now that I look at it, I was SOOOOO wrong about the $result_ar thing...Ack!Looking at what the code actually does, there are far easier ways to accomplish what you are trying to do with that script...I don't know if a rewrite is an option...[/quote]Thanks anyway, i did make the code with only 1 <?php .....code......?> and it did work...Thanks for the reminder... Quote Link to comment https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.