andrew_ww Posted January 8, 2007 Share Posted January 8, 2007 Here's the code which generates the error, anything look out of place ? [code][/code] Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/ Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 not much to see there ?? Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156196 Share on other sites More sharing options...
andrew_ww Posted January 8, 2007 Author Share Posted January 8, 2007 I'll try again:[code]<?php// Get MySQL connectionrequire_once('../required/conn.php');// Begin sessionif (!isset($_SESSION)) { session_start();}// If user session is not set redirect to login pageif(!isset($_SESSION['authenticated'])) { header("location: ../?notification=pleaselogin");}// Logout link$logout = $_SERVER['PHP_SELF']."?begone=true";// If user chooses to logout unset session and redirectif(isset($_REQUEST['begone']) && $_REQUEST['begone'] == true) { $_SESSION['authenticated'] = NULL; unset($_SESSION['authenticated']); header("location: ../index.php?notification=loggedout");}// Get user's ID from session$userID = $_SESSION['authenticated'];?><?php require_once('../Connections/db.php'); ?><?php$IP_LOG = $_SERVER["REMOTE_ADDR"];$HOSTNAME_LOG = gethostbyaddr($_SERVER['REMOTE_ADDR']);?><?php$colname_rs_table1 = "1";if (isset($_GET['recordID'])) { $colname_rs_table1 = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);}mysql_select_db($database_db, $db);//$query_rs_table1 = sprintf("SELECT * FROM tbl_table1 INNER JOIN table2 ON (tbl_table1.id = table2.id) WHERE table2.id = %s", $colname_rs_table1);$query_rs_table1 = sprintf("SELECT * FROM table2 WHERE table2.id = %s", $colname_rs_table1);$rs_table1 = mysql_query($query_rs_table1, $DII) or die(mysql_error());$row_rs_table1 = mysql_fetch_assoc($rs_table1);$totalRows_rs_table1 = mysql_num_rows($rs_table1);?><?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""){ $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE table2 SET sub=%s WHERE id=%s", GetSQLValueString($_POST['sub'], "text"), GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_db, $db); $Result1 = mysql_query($updateSQL, $db) or die(mysql_error()); $updateGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo));}?> [/code] Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156198 Share on other sites More sharing options...
Asheeown Posted January 8, 2007 Share Posted January 8, 2007 Personally I haven't worked with header functions much but the ".." just doesn't look right in those Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156199 Share on other sites More sharing options...
andrew_ww Posted January 8, 2007 Author Share Posted January 8, 2007 Which bit are you referring to ? Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156200 Share on other sites More sharing options...
fert Posted January 8, 2007 Share Posted January 8, 2007 place[code]ob_start();[/code]at the very top of your scriptand [code]ob_end_flush();[/code]at the very bottom Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156204 Share on other sites More sharing options...
chronister Posted January 8, 2007 Share Posted January 8, 2007 which line is the header being sent by....The only reason to get this error is that your code is outputting to the browser before you are trying to do the header call. Make sure you are not echoing anything, or no other html is being outputted. OR wrap the whole thing in ob_start() at the beginning, and ob_end_flush() at the bottom.also did you read this http://www.phpfreaks.com/forums/index.php/topic,37442.0.htmlIt is on the main page of php help titled HEADER ERRORS - READ HERE BEFORE POSTING THEM Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156207 Share on other sites More sharing options...
andrew_ww Posted January 8, 2007 Author Share Posted January 8, 2007 I've added the ob_start and the ob_end_flush function to the script and now it works.What exactly do these functions do ? Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156209 Share on other sites More sharing options...
fert Posted January 8, 2007 Share Posted January 8, 2007 they buffer any output the script produces Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156210 Share on other sites More sharing options...
chronister Posted January 8, 2007 Share Posted January 8, 2007 ob_start starts output buffering... meaning it parses the whole page before it sends to the browser.ob_end_flush, ends the output buffering and then flushes (sends to the browser) Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156211 Share on other sites More sharing options...
andrew_ww Posted January 8, 2007 Author Share Posted January 8, 2007 So is this is an acceptable solution ?I've tried and failed to identify the whitespace with no success. Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156217 Share on other sites More sharing options...
genericnumber1 Posted January 8, 2007 Share Posted January 8, 2007 the whitespace in your script would be where it goes[code=php:0]// php here?><?php// more stuff[/code]that stuff in between is white space that is outputted to the browser.just remove them![code=php:0]// php here// more stuff[/code] Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156218 Share on other sites More sharing options...
chronister Posted January 9, 2007 Share Posted January 9, 2007 Yes, ob_start and ob_end_flush are acceptable, however I agree with genericnumber1 , since all the code is php just have a <?php to start and ?> to end you are starting and ending php several times[code]$HOSTNAME_LOG = gethostbyaddr($_SERVER['REMOTE_ADDR']);?>//whitespace//whitespace//whitespace <?php$colname_rs_table1 = "1";[/code][code]?>//whitespace<?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""){[/code]remove those whitespace lines and your code should be golden Link to comment https://forums.phpfreaks.com/topic/33403-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-156320 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.