PHP Session Warnings: what to do [duplicate] - php

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/moonpk/public_html/wallz/preview.php:16) in /home/moonpk/public_html/wallz/loginbox.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/moonpk/public_html/wallz/preview.php:16) in /home/moonpk/public_html/wallz/loginbox.php on line 2
i am getting these two warning which i was not getting on local server... why ....

See the first note on the php session_start() page. session_start() sends cookies to the browser, and the server will not send any additional data (including cookies) after any data has already been sent. This can simply be fixed by making sure that nothing is being sent to the browser (such as an echo() or var_dump() call) before calling session_start().

You don't get them on local server because you have lower errer reporting level on it. So, you need:
On you local server edit php.ini and set error_reporting to E_ALL
Move you session_start() call before line 16 of you /home/moonpk/public_html/wallz/preview.php file

Most likely you have some whitespace outside any PHP-tags in files that are loaded before the session_start() is executed. Maybe your FTP client messed things up?

You probably had warnings suppressed on your local server? The issue is that you have some output before you call session_start. Judging by the line numbers, I'd guess you have a line break before your opening php tag, but without seeing the code, can't provide a full solution.

If you are including the page "preview.php" within "loginbox.php" check that you have only called session_start once on one page.
Either on preview.php or loginbox.php , not both.

Related

Session start on an empty page causes an error; session_start(): Cannot send session cache limiter

Hi I have a php file that is empty and the only line of code in there is
<?php session_start(); ?>
No html mark-up or any php code besides the code above.
On localhost it doesn't trigger an error, but when it's on the server and I visit the page, a new line is printed on the error log that says
[25-Apr-2016 05:43:34 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at path/to/file.php:1) in /path/to/file.php on line 1
The server is running apache and php 5.6 if that's relevant, I've also tried deleting the .htacces file just in case that is what's causing the problem but still no luck.
Can anyone point me in the right direction to see what may be causing the issue? Thanks!
Problem : Sometimes there are invisible characters inside your code file.
Solution :
So simply for now if want to fix the error so here is the quick way to do it :
I am sure you must be using some sort of Code Editor just simply save your php file with encoding as "UTF-8 With BOM" and then upload the saved file to your site and then access your file and you will have no problem..!
Screenshot For Better Guidance :
Reference URL :
How to fix "Headers already sent" error in PHP
If that doesn't solve your problem so then use this solution :
Make sure there is absolutely no whitespace before <?php
Put session_start() before ob_start() instead of after it.
If that fails, try commenting out the session_start() as one of your
includes might already be starting the session, like so: /** session_start(); **/

How to fix session problems on web host when header location change?

When execute header("Location: new/location.php") command I got session problems.
On local host testing everything works just perfect, but if i send my project on web server hosting i got these errors:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /srv/disk4/2008248/www/some-url.com/new/location.php:2) in /srv/disk4/2008248/www/some-url.com/new/location.php on line 7
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /srv/disk4/2008248/www/some-url.com/new/location.php:2) in /srv/disk4/2008248/www/some-url.com/new/location.php on line 7
, so my question is how to fix this problems and keep session values alive, so i can use that values in another redirected page?
Warning: session_start(): Cannot send session cookie - headers already... a typical error when something is before session_start()
You need to write session_start() above headers(). As error says you already sent something beforee session start. Make Session start the very first line of your script, and leave no spaces before <?php tag
use ob_start(); on top of the php page

i have uploaded my project on the server but when i try to run it it shows this warning [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 7 years ago.
i have uploaded my project on the server but when i try to run it it shows this warning. However on my local machine every thing is working just perfect what could be the problem.
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/prosyst2/public_html/sms/index.php:1) in /home/prosyst2/public_html/sms/auth.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at /home/prosyst2/public_html/sms/index.php:1) in /home/prosyst2/public_html/sms/auth.php on line 8
You can't set session/cookie after you echo'd something or generated some output.
You can use ob_start(); at the beginning of the file and echo ob_get_clean(); at the end to buffer the output.
Your local php installation does not report warnings correctly, set it to report E_ALL, which is errors, warnings, notices etc, and the other way on the server.
When it comes to your specific problem, you have output before your session_start(); call, this could be html or anything that writes to the output buffer, or incase session_start(); is on the top of the page, possibly a BOM character.
How to fix:
Never do any output before sending headers (header(...), session_start() etc) and this wont happen.
Always report all errors and warnings etc on a development installation, so you know whats wrong.

PHP Warning Cannot Modify Header Information [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
My site is running fine on one server but when I shifted it to another server, some pages are giving following warning message.
Warning: Cannot modify header information - headers already sent by (output started at /home/parviz/public_html/ganj_videos/lang/english.php:1) in /home/parviz/public_html/ganj_videos/mobile/detect.php on line 50
Any idea on how to fix it?
Thanks.
Most likely your new server has a different setting for the errors and warnings. If PHP issues a warning or error as output then it will cause your headers to fail.
Change the level using the error_reporting function.
Just follow the debug: it says output started in file /home/parviz/public_html/ganj_videos/lang/english.php on line 1. There's most probably some messy newlines or spaces there. Make sure all php files executed start with <?php and NOTHING else before it, or you'll get the warning.

$_SESSION Problem

I have recently changed my editor to save int UTF-8. This started poping out afterwards and don't know what it means.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sudancar/public_html/index.php:1) in /home/sudancar/public_html/index.php on line 1
Your editor most likely wrote out a BOM (Byte-Order-Marker) to indicate that the file was UTF-8.
Because that marker appears before any <?php tags, PHP automatically sent it to the browser, including the necessary headers.
Unless your PHP can be compiled with the experimental (--enable-zend-multibyte) option, it can't be helped. You'll just have to tell your editor not to write that marker.
For reference: http://bugs.php.net/bug.php?id=22108
You need to call session_start() before ANY output is sent to the browser.

Categories