jeff5656 Posted September 5, 2012 Share Posted September 5, 2012 I get the above error, even though I am not echoing anything out. Is there something int he following code that gets echoed out? The word "echo" does not appear in this page at all! It is a page that processes a script so there is no html in it. No <head>, etc etc. if ($_REQUEST[completed] == 1) { move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = mysql_real_escape_string(fread($instr,filesize("latest.img"))); if (strlen($instr) < 1000000) { mysql_query ("insert into pdf (title, imgdata, category, jl_date, jl_type, description, ref) values ('$title','$image', '$category', '$jl_date', '$jl_type', '$description', '$ref')"); $_SESSION['errmsg'] = "Done"; } else { $_SESSION['errmsg'] = "Too large!"; } } else { $_SESSION['errmsg'] = "PDF not uploaded"; }} header("Location: ".$_SESSION['loc']); Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/ Share on other sites More sharing options...
Adam Posted September 5, 2012 Share Posted September 5, 2012 Do you have any white-space before the opening PHP tag? The error should tell you where output was started. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375410 Share on other sites More sharing options...
jeff5656 Posted September 5, 2012 Author Share Posted September 5, 2012 I can't tell if I have any white spaces. However, in dreamweaver I switched to design view and that page is blank with no characters to delete, so I do not think I have any white spaces. Are you saying that if I use the space bar when coding, it will come out as a white space? How can I tell the difference - do I need to scrunch everything together o there are no spaces? Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375414 Share on other sites More sharing options...
Pikachu2000 Posted September 5, 2012 Share Posted September 5, 2012 The error message tells you where the output is sent. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375416 Share on other sites More sharing options...
Christian F. Posted September 5, 2012 Share Posted September 5, 2012 Is this file included by something else, by any chance? Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375417 Share on other sites More sharing options...
premiso Posted September 5, 2012 Share Posted September 5, 2012 Did you by chance read the sticky in this forum that is in all caps and tried what it suggested? HEADER ERRORS - READ HERE BEFORE POSTING THEM Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375439 Share on other sites More sharing options...
jeff5656 Posted September 5, 2012 Author Share Posted September 5, 2012 "Did you by chance read the sticky in this forum that is in all caps and tried what it suggested?" Yes I did. Which part were you referring to? Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375459 Share on other sites More sharing options...
jeff5656 Posted September 5, 2012 Author Share Posted September 5, 2012 Do you have any white-space before the opening PHP tag? The error should tell you where output was started. I went back and deleted all quesiton of any white spaces and still get the error. The error points to line 19 which is this line: if (strlen($instr) < 1000000) { Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375460 Share on other sites More sharing options...
premiso Posted September 5, 2012 Share Posted September 5, 2012 Yes I did. Which part were you referring to? The whole thing. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375468 Share on other sites More sharing options...
Pikachu2000 Posted September 5, 2012 Share Posted September 5, 2012 The error message tells you where the output is sent. Post the exact error. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375469 Share on other sites More sharing options...
jeff5656 Posted September 5, 2012 Author Share Posted September 5, 2012 The error message tells you where the output is sent. Post the exact error. Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/f/user1234/html/education/add.php:20) in/home/content/j/e/f/user1234/html/education/add.php on line 32 Line 32 is the last line of add.php that says header(location etc.. line 20 is the line I specified above as line 19. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375538 Share on other sites More sharing options...
Jessica Posted September 5, 2012 Share Posted September 5, 2012 If that's line 19, we're missing a good 15 lines of your code? Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375542 Share on other sites More sharing options...
The Little Guy Posted September 5, 2012 Share Posted September 5, 2012 If you are including another php that may have issues. Usually it is good NOT to close your <?php tags, unless there is more non-php (html). If you do close them and have an unknown space, or new line after it, the file including it will see that as output. If you don't close the tag and have many newlines or spaces the PHP file will ignore those lines. <?php require_once "some_file.php"; // This will not throw an error require_once "some_file2.php"; // This will throw an error header("Content-Type: text/plain"); echo $var; some_file.php <?php $var = "some php code"; some_file2.php <?php $var = "some php code"; ?> Hope that makes sense. If that is not the cause are you sure you have valid php? Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375545 Share on other sites More sharing options...
Christian F. Posted September 6, 2012 Share Posted September 6, 2012 I'm certain that it's not the only error you have, Jeff, at least not if you have error reporting turned on properly. I suspect that you're also seeing a notice about an undefined constant, which would explain the line numbers in the headers already sent error message. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375671 Share on other sites More sharing options...
MDCode Posted September 6, 2012 Share Posted September 6, 2012 Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/f/user1234/html/education/add.php:20) in/home/content/j/e/f/user1234/html/education/add.php on line 32 Line 32 is the last line of add.php that says header(location etc.. If you have any html before the header location, it will give that error. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1375729 Share on other sites More sharing options...
jeff5656 Posted September 7, 2012 Author Share Posted September 7, 2012 I didn't include the whole file because it didn't contain any output, but here is the entire file. I can't fnd anything int his file that would give me that error message because there is nothing being echoed out. here it is: <?php session_start(); include "../connectdb.php"; // Store the .pdf $description = mysql_real_escape_string($_POST['description']); $category = mysql_real_escape_string($_POST['category']); $_SESSION['category']=$category; $title = mysql_real_escape_string($_POST['whatsit']); $ref = mysql_real_escape_string($_POST['ref']); $jl_date = mysql_real_escape_string($_POST['jl_date']); $jl_type = mysql_real_escape_string($_POST['jl_type']); $jl_type_sub = mysql_real_escape_string($_POST['jl_type_sub']); if ($_REQUEST[completed] == 1) { move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = mysql_real_escape_string(fread($instr,filesize("latest.img"))); if (strlen($instr) < 1000000) { mysql_query ("insert into pdf (title, imgdata, category, jl_date, jl_type, jl_type_sub, description, ref) values ('$title','$image', '$category', '$jl_date', '$jl_type', '$jl_type_sub', '$description', '$ref')"); $_SESSION['errmsg'] = "Done"; } else { $_SESSION['errmsg'] = "Too large!"; } } else { $_SESSION['errmsg'] = "PDF not uploaded"; } header("Location: ".$_SESSION['loc']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376151 Share on other sites More sharing options...
The Little Guy Posted September 7, 2012 Share Posted September 7, 2012 according to the way you posted, you have white space above <?php Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376157 Share on other sites More sharing options...
jeff5656 Posted September 10, 2012 Author Share Posted September 10, 2012 according to the way you posted, you have white space above <?php No. The <?php is on line 1 of the file. So no one else can find any why space in the file? Weird eh? Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376761 Share on other sites More sharing options...
premiso Posted September 10, 2012 Share Posted September 10, 2012 From the link I posted earlier on: Documents encoded in UTF-8 are becoming more and more common. Many programs, however, will add a byte order mark at the very beginning of UTF-8 encoded documents. This appears invisible in the editor and is actually placed before any text you write. This can be a problem when working with PHP scripts. PHP treats the byte order mark as text that needs to be output, and this will happen before it starts executing any PHP code, even if the PHP code appears at the very beginning of the document when viewing it in an editor. Now, the issue here is that you don't get a chance to start output buffering (ob_start()) or call any functions that manipulate the HTTP response headers (session_start(), setcookie(), header() and so on) before the output is started. All of this can be avoided if you make sure that your favorite editor saves your documents without the byte order mark or, alternatively, by enabling output buffering in php.in My bet is your editor is dishing out the Byte Order Mark Check your editor's preferences, or let us know what editor you are using so that you can be assisted to turn it off, re-save and see if that solves your problem. Alternatively, as also mentioned in that topic, you can turn on Output Buffering in Apache which will save all output to the end of execution and should prevent the error from occuring, although that is looked more of a bandaid, it still works. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376763 Share on other sites More sharing options...
PFMaBiSmAd Posted September 10, 2012 Share Posted September 10, 2012 The output that is occurring on about line 20 of your file - if (strlen($instr) < 1000000) { is because that line is giving a warning message, that you apparently ignored and didn't tell us about - Warning: strlen() expects parameter 1 to be string, resource given in your_file.php on line 20 It's not just the last message that you get that is important. You are getting the error on line 20 because $instr is the file handle from the fopen() statement. It is not a string. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376768 Share on other sites More sharing options...
jeff5656 Posted September 10, 2012 Author Share Posted September 10, 2012 Great thanks for that pickup! I never would have figured that out. I don't really understand that line, but I guess I will google around and find a better way to upload a file the database. I think this is one option: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376783 Share on other sites More sharing options...
Christian F. Posted September 11, 2012 Share Posted September 11, 2012 I would not use that code: It's old, severely outdated, and completely insecure! In addition to that, I would not have saved the files themselves in the database, but directly on the file system; That's what it's meant for, after all. Better to just store the path/filename in the database, and use it to retrieve the file. Quote Link to comment https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/#findComment-1376929 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.