I am trying to use the session start function but everytime I try to use it, it gives 2 errors:

Cannot send session cookie - headers already sent by (output started at /var/www/form/send.php:11) in /var/www/form/send.php on line 12

Cannot send session cache limiter - headers already sent (output started at /var/www/form/send.php:11) in /var/www/form/send.php on line 12

What could be the problem(s)?

Details:
I am running apache2 on Ubuntu and using the netbeans IDE for the programming and testing.
However, when I uploaded it to my website it still gives the same errors(just different pathnames).

You cannot have any output prior to the session start. Thus, you can't echo anything or have any text coming from any html. If you haven't done this intentionally, it can sometimes be the result of a blank line (e.g. an empty line before the intial <?PHP)

yeah this is like the header("location: sample.php"); you cant have any output before the session_start() even spaces, newline, tab etc. or else it will generate an error

Member Avatar for rajarajan2017

Delete all the files in the tmp directory of the webserver and execute again.

redirect not working if you have any echo in your page
delete any echo and try again
delete any empty space before <?php ?>

Thanks for the replies... Turns out I had some html (which is still in the php templates when I create new files) tags like <html> <head> and <body>. I deleted all the HTML from the script and works like a charm. Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.