Welcome Guest, Not a member yet? Register   Sign In
Headers Already Sent - already read all the other posts on this matter
#1

[eluser]Unknown[/eluser]
First off, just started using CodeIgniters yesterday and I've been very happy with it.

However, I finished up the main pages and went to add users. Auto loaded the session library, and have the same issue so many others have mentioned:

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\system\codeigniter\Common.php:130)

Filename: libraries/Session.php

Line Number: 662

Now, I've just spent the last 3 hours or so searching the forums, google, even some forums of other projects that are built on CI - so please don't think I'm posting here because I don't know how to read something that is clearly defined in 25 different threads. The issue is that none of those steps worked Smile

What I've tried:
1. checked all MY files, and a number of the CI files to ensure nothing was before or after the php tags (if they had ending tags....)

2. I'm using Notepad++, and there was some mention of that along with character encoding. I first encoded various files in ANSI (which was what they were by default for me) but also tried UTF-8 without BOM as suggested.

3. I used Notepad (ms notepad) and opened up various files and saved them after ensuring nothing was before or after the tags

4. I removed my htaccess file text, saved, tried again (that was mentioned that it could cause it, and I have an entry that I found to fix the path names in there).

5. Lastly, something strange (again, after hours of searching you try anything right?):
I'm using php 5.3.1 so with full E_ALL turned on, I get the "deprecated" warnings since CI creates object by ref. I went to line 130 in common per the error, and removed the "&" to correct this....and the first output then became 136...removed it there and it ended up in exceptions (or somewhere, i don't remember). eventually i got to a point where there was not class declaration on the deprecated code, i didn't know what to remove. It didn't fix a thing, just lead me on a wild goose chase that probably woulda lasted a while. but, the fact that it changed the first output line makes me think it could be important to someone who knows this better than I do.


I'm at a loss here. From what I know about building my own session libraries in the past, I'm assuming it won't work with this error. This puts my work on a standstill as I need to get the session figured out before proceeding

One last thing: My output files all have opening and closing php tags all throughout them, but I'm assuming thats normal. I've tried it with the prebuilt 404 page as well.
I also need to know what files I should be focusing on here. There error is in a CI file, from a CI file....but I obviously haven't changed those! Trying another editor, what files should I be opening and saving?

EDIT: it just occurred to me that the error logging is what's outputting prior to the session call (see #5). Going to try turning off errors and warnings, and test a quick session (since that shuts off the header error message as well).
#2

[eluser]jedd[/eluser]
Hi greatkingrat and welcome to the CI forums.

One thing you didn't say - and is the other item covered in the wiki and most other posts on this subject - is to look for echos, print_rs, var_dumps, etc - in your models, controllers, libraries and helpers - as this can cause the same error.

Can I also suggest you install [url="http://git-scm.com/"]git[/url] and use it - as you know, coding php is a heavily iterative process, and using git's bisect feature you can quickly identify the change you made that introduced this (kind of (and many other kinds of)) bug.

Presumably you've since removed closing php tags from your project files that don't need them (controllers, models, libraries and helpers). It's generally advised (by php types, not just CI types) to eschew closing tags.

Do you get this error on every page load? Are you autoloading any of your own libraries or models - such that you can remove those autoload entries and narrow down the likely problematic file? I know - this is getting very close to egg-sucking advice on troubleshooting code.
#3

[eluser]NMTeck[/eluser]
One thing I've learned from programming is that computers and code, do exactly what you tell them to do. With the session issue, that's one I've come across a few times myself. It definitely has to do with some output being loaded before the session is started.

As I'm sure you know, the session needs to be the first things loaded. There may be somewhere that you are trying to output some debug info and that's causing you to get the error.

Are you loading the session in your controllers? If you are, try adding it to autoload.php and the array in that file. This will load the session CI style and before any code you have has a chance to be executed.

That may work for ya.
#4

[eluser]Unknown[/eluser]
Opps I though I had already responded to this explaining the solution!

It was the error messages. Because using e all output the wanting on old functions, and it did so before the write to the headers. It's kind of odd to say I turned off error messages and everything works, since you can't see the errors, but it does. The warnings were what was output before the headers




Theme © iAndrew 2016 - Forum software by © MyBB