0

I have a bizarre problem with using session_start() function. I have narrowed down my code to just two lines and uploaded the same to web server for testing. Here is my code :

                <?php
                session_start();
                echo "hi";
                ?>

But the following messages are coming up onto the web browser:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/dchcov5r/public_html/demo/application/temp1.php:1) in /home/dchcov5r/public_html/demo/application/temp1.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/dchcov5r/public_html/demo/application/temp1.php:1) in /home/dchcov5r/public_html/demo/application/temp1.php on line 2

I am using Dreamweaver as my developer tool. This question may look similar to How to fix "Headers already sent" error in PHP but since I tried all or may be failed to efficiently implement the solutions provided therein, being a novice developer asking for pin-pointing the most probable cause because that thread shows so many answers.

Also, is it due to server settings in the web hosting or in php.ini file, because my code worked perfectly fine in localhost i.e. XAMPP.

Community
  • 1
  • 1
samlancer
  • 141
  • 2
  • 13
  • do you have any whitespace before your ` – chriz Mar 21 '15 at 17:29
  • No. the code in the file has no white space. I have put it here for stackoverflow.com guidelines. @chriz – samlancer Mar 21 '15 at 18:13
  • The problem is in file `temp1.php` on line 2. Firstly, make sure you are editing the right file! Also, what file encoding are you using for your PHP files? There will probably be a setting in DreamWeaver to specify UTF-8 etc when saving. I wonder if you have an invisible character in there. Try using another text editor to load this file, to see if there is anything prior to the opening PHP tag. – halfer Mar 21 '15 at 18:29
  • Thanks halfer. But I investigated the php.ini setting in my cpanel hosting, there I saw that no value was set for output_buffering. I am pretty sure that output_buffering is the only difference from my localhost setting and cpanel setting. But again I looked into the manual for output_buffering which says that output_buffering = 4096 (in production env) may help me to send header info even if the same already sent. Is it healthy to use value for output_buffering? – samlancer Mar 21 '15 at 18:39

0 Answers0