I recently migrated from a Windows to Linux server... now I am getting a bunch of session warnings and some of the content is being loaded properly. On the Windows server, everything worked smooth and I never had any errors, as soon as the migration to Linux took place, I started getting session warnings such as the one below on every page that uses sessions.
I have no idea what I should try or where to begin to address these problems and would appreciate any advice.
I suspect that if session_start() was actully was the problem, I would have gotten a similar warning on the Windows server.
Also my site is hosted by goaddy and I do not have access to the php.ini file...
Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started
at /home/content/12/9453412/html/mainsearch.php:32)
in /home/content/12/9453412/html/mainsearch.php on line 36
Your problem is, that in
/home/content/12/9453412/html/mainsearch.php line 32
(and possibly also in the following ones) you do some kind of output (echo, print, blanks outside of <?php ... ?> etc.), before you do session_start(); on line 36. This is not allowed, as session_start() wants to send headers which is not possible after some kind of output already occured.
Solution: Put your session_start(); to the top of your php file, or at least before you do any kind of output.
And Michael pointed out correctly that this didn't work correctly on you Windows server either, you just didn't know because error reporting was set not to display warnings.
Related
I have a problem while publishing my site. I have a autentication system using session by codeigniter.
When it's run on localhost, its perfect. But when i publish in the server (hosting godaddy), It display this message
Severity: Warning
Message: session_start(): Cannot send session cookie - headers already
sent by (output started at
/home/cristiandelacruz/public_html/crmappsdc/application/config/config.php:1)
Filename: controllers/Login.php
It means you have something output on browser while redirection.
You can do following things:
1) Check which code is printing HTML. And remove it.
eg. Spaces, echo or print statements.
2) if this does not work, add ob_start (); at the file beginning. It stores output in buffer and redirection occurs.
Check if you have blank space before php opening tag in message mentioned file. Try again to save that file without BOM (Copy content into new file and double check you don't have blank space or any characters before file start and save it encoded in UTF-8 without BOM). Maybe helps.
this is happening because your local environment does not have full error reporting turned on, while your hosting provide does. The problem is most likely always there. The reason to that problem is most likely that you are calling Codeigniter's session class $this->session-> ... , however somewhere in the loading of your application, PHP already encountered this: session_start(). To fix it, you need to debug your program and find out where the session is being initialized because the way its currently set up, it is being initialized twice.
Cause:
This error is caused if the your PHP scripts are printing to the browser prior to sending headers. A common example is printing the html tags prior to starting a session, or setting a cookie. The error tells the line that needs to be altered (in this case, it is on /config.php).
Resolution:
To resolve this error remove the lines from the PHP code that are printing to the browser prior to sending headers.
Another common cause for this error is white space either at the beginning or end of the file. The fix is to remove that whitespace from the file. Read the error message carefully. It says output started at ... followed by a file name and a line number. That is the file (and line) that you need to edit. Ignore the second file name - that is only a file that included the file that has the whitespace. The first file is the one you have to edit, not the second one
Source from WHAT DO I DO WHEN I RECEIVE A PHP HEADER ERROR MESSAGE? GoDaddy Forum
Codeigniter Seesion class
I tried above all solutions. finally, I Changed output_buffering in PHP.ini (GoDaddy Server)
output_buffering = on
In PHP 5.4 version by default output_buffering has no value
I updated the PHP version 5.4 to 5.6 and in 5.6 version by default it has value 4096
Now it's working fine
I have a DMZ set up with a web server and an application server, both running Ubuntu under gnome (v11.04 on the web server and v11.10 on the application server). session_start() has started hanging on the application server. The code is located on the application server and it does not hang when I access my web site and access the page with the session_start() call on it. It seems that every session_start() has started hanging on the application server although I have no problems with the associated pages when I access them from other computers or across the web. Also I have only just started having this problem on the application server without having made any changes to my php code. Could it be that some buffer has filled up and needs to be cleared?
I tried editing /etc/php5/apache2/php.ini and setting
session.save_path = "/tmp"
/tmp exists.
But I still have the problem. I can stop it hanging by preceding session_start() with session_end() but then it does not execute the remaining PHP or html code in the file.
/var/log/apache2/error.log included the following message:
PHP Notice: A session had already been started - ignoring session_start() in
/var/www/DraculaPgm.php on line 101, referer:
http://MyWebSite.com/ApplicationServer/Dracula.php
Any assistance with this would be greatly appreciated,
Peter.
Update 29-Dec-2012
Thank you to everyone who replied to this question. Unfortunately, I tried all of the suggestions and 'session_start()' still hangs. However, if I leave it for a few minutes, it breaks with the following error message.
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /ApplicationServer/Dracula.php.
Reason: Error reading from remote server
Apache/2.2.17 (Ubuntu) Server at MyWebSite.com Port 80
I have squid installed on the web server. Could this be a problem?
Thanks,
Peter
This sounds like a configuration issue. Make sure that PHP is reporting all errors, i.e., error_reporting(E_ALL) and either display or log all errors. (You might even want to enable display_startup_errors in your php.ini) - reporting all errors may shed light on what's going on. (if you need help you can post any errors that you get from this as an edit) You may want to look at the following as well for troubleshooting the issues with sessions:
When using /dev/random as session entropy file
When page is calling itself with the same session
Alternatively if none of those show anything you may want to read over the bug report at https://bugs.php.net/bug.php?id=28856&edit=1 depending on what version of PHP you are running.
I changed 'session_start()' to the following block.
if(!isset($_SESSION))
{
session_destroy();
session_start();
}
I now do not have the problem. I am hesitant to say that it fixed the problem since it did not seem to fix it right away.
Thank you to everyone for your help,
Peter.
Try changing the permission of the /tmp folder by doing chmod 777 /tmp and check if its working.If its working then change the permission mode to make it more secure
Try checking out this Question I call session_start() the script hangs and nothing happens
And this http://www.projectpier.org/node/1934
"It seems that the session file is opened exclusively. On some
occasions (Windows) I have found that the file lock is not released
properly for whatever reason, therefore causing session_start() to
hang infinitely on any future script executions. My way round this
problem was to use session_set_save_handler() and make sure the write
function used fopen($file, 'w') instead of fopen($file, 'x')"
You can find many others having the same problem and their workarounds if you go through http://php.net/manual/en/function.session-start.php
if(!isset($_SESSION))
{
session_start();
}
Use this at the top of your PHP file!
And for your info: session_destroy() is used to end session.
Before anything else - try another browser!
I just encountered this session_start problem. I checked my tmp folder and everything and I was about to call my hosting-provider until I thought I should try another browser first because it might have to do with session cookies.
I work with chrome, so I tested in IE and found that it was indeed the case: It worked in another browser!
I closed IE ;) - went back to chrome, looked for the cookie (PHP_SESS_ID), deleted it and everything works again!
Well, the good part is - Just like you guys I got to brush up my knowledge of -jay- sessions! ;)
I developed a php project in WebMatrix on IIS. In this project I accidently initialed same "session variable" twice.
Example: File - a.php
<?php
$_Session['one'];
include 'b.php';
...........
...........
...........
...........
?>
Example: File - b.php
<?php
$_Session['one'];
...........
...........
...........
...........
?>
When I run this project from Webmatrix(IIS server) this error wasn't shown but when I ran this project on Apache this error was displayed and I corrected my flaws.
Warning on Apache:
Notice: A session had already been started - ignoring session_start() in D:/path/.
My question is that why this error was not shown earlier? Is it something related to IIS server or WebMatrix. I always need to be aware of the errors or warnings in the code so that I can get rid of them and the efficiency of the code is sustained, please do suggest me some ideal php develeopment tools which can catch even minor errors in my code.
Ensure errors are being displayed and then try turning error_reporting all the way up at the beginning of the application.
ini_set('display_errors', 1);
error_reporting(E_ALL);
Also, be aware that Windows is not case-sensitive. You could say include 'A.php' or include 'a.php' and it would not care. However, when you put it on a Linux-based server, which is case-sensitive, it may not be able to find the file A.php if its actually a.php.
It's possible you got errors because the first server was running PHP 4 and the second is PHP 5. Double-including a file containing functions will get different results in those versions. See the text just before example 6 in this link: http://php.net/manual/en/function.include.php
EDIT: I believe the error messages generated in your edited post indicate something of a different nature.
For files that you want to make sure they are only included one time, use include_once(). http://www.php.net/manual/en/function.include-once.php
There are some situations where you may legitimately want to include() twice from a file. But because those situations are rare, it's best to use include_once().
Warning on Apache:
Notice: A session had already been started - ignoring session_start() in D:/path/.
You can't start session again which is already started.
You need 1 session start at a.php when you include b.php it can use started session.
Its a warning and warning means its not good but php can fix this error and continue working.
Its all about error reporting level.
It is hard to tell if the error didn't occured on IIS or not. Only because it was not displayed or logged, does not mean it didn't occur. Please compare the error reporting php.ini configuration between both systems.
Another thing you should compare in configuration is if session auto-start had been enabled on the old or new system or not. This might be triggering your error, but it's only a guess. As written the error might have been already on the old system but just was unnoticed.
I'm creating a plugin for joomla and it is working as expected in my local Windows 7 machine with WAMP. But when I load the plugin into the production server(Debian), I get this warning (not always):
Warning: Cannot modify header information - headers already sent by (output started at /httpdocs/plugins/system/fiuser.php:1) in /httpdocs/plugins/system/jat3/core/parameter.php on line 73
I tried googling, but it didn't helped me solve the problem actually.
<?php
defined('_JEXEC') or die('Restricted Access');
class plgSystemFiUser extends JPlugin {
// Some functions
}
I get this warning whenever I delete the browsing data from the browser and then the problem persists until I close the browser or go to an another site.
Content of line 73, parameter.php:
setcookie ($this->template.'_tpl', $this->template, $exp, '/');
I'm finding it difficult to debug this problem, as I'm not too much experienced with Joomla and PHP, so any help is appreciated a lot.
Remove the closing ?> tag at the end of your PHP files. It actually serves no useful purpose as the PHP interpreter knows that end-of-file means end-of-PHP too. Removing it means that any extra blank characters added by your editor will have no effect on the output generated and so will not prevent additional HTTP headers from being sent.
Turn output_buffering setting on php.ini to on to permanently remove this error
There is a conflict of the header() method, take a look at flushing the output buffer
PHP.net Output Buffer methods
Warning: Cannot modify header information - headers already sent by (output started at /home/content/82/6985782/html/wordpress/wp-content/themes/syntax/themeoptions.php:289) in /home/content/82/6985782/html/wordpress/wp-content/themes/syntax/themeoptions.php on line 136
Thats the error i get whenever i want to submit something in the admin panel.
Here's the code for the themeoptions.php:
http://pastebin.com/aFWHjEv0
It all works perfectly normal on localhost, any explanations??
It's probably output_buffering that is enabled on your local machine, but not on the remote server. (You can find out by using phpinfo).
The easy fix is to prepend your script with a output_buffering command:
<?php
ob_start();
Even better is finding out where the output starts and fix it there.