Warning: session_start()

warningToday while creating a WordPress plugin, i got an error when I activated it. Although this was not the first time i was developing a plugin for WordPress, but the error was there and seemed as if my plugin is conflicting with another plugin called Membership Pro.

The error was:

Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at…

WordPress also gave me this error:

The plugin generated 5 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

At first i didn’t understand, why is this error there! Tried a few things to solve it along with checking out the Membership Pro plugin files but then I realized that this error popped only after activating my very own plugin!

So, i took a plunge at my plugin file, and i came to end, and noticed that there are no errors neither in functions nor in other coded lines. But then, It stroked me that I got this type of error once while I created functions.php file for a theme. Well, I got my solution. The solution was:

But be sure that this one is the second or last attempt to avoid this error. Because this plays with the output buffer; once it messed up with the session values for me.
some empty lines after the end of plugin ( ?> ) which were causing the headers to be generated before your plugin code executed the headers.

Your first step towards debugging this error should be this way. The solution is simple, go to the plugin from which you have the error, (usually the first file to be mentioned is the one with the error) and make sure that there is no empty space before


and after


and it will work perfect! For you self satisfaction, you can re-type the opening and closing part of PHP i.e. ‘<?php’ and ‘?>’. Also, it’s always recommended to use the full form of ‘<?php’ while you start the PHP and not the short form (<?php and ?>).

Thanks for reading this post and as usual, I’m open to suggestion and critics (positive of course).
Do comment on!


Post Author: Shreyo

is a developer & involved in project management; loves to learn, guide and keep himself updated on UI/UX and WordPress. He is also an amateur photographer mostly macro shots.
  • Aneita

    the post is really very interesting and informative…

  • Brenda

    i am really impressed by your post!