0

I am getting an error related to session_start() on page load.

Warning: session_start(): Cannot send session cache limiter - headers already sent

I understabd from the previous posts that we are supposed to put it right at the beginning of the page even before all HTML. So I changed my code to this:

    <?php
    if(session_id()=='')
    {
       session_start();
    }
    if (!isset($_SESSION['can_access']) || ($_SESSION['can_access'] != TRUE))
    {
       echo "Access denied";
       exit();
    }
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge chrome=1" />


 </head>
 <body>

But I still get this error. Could anyone suggest what could be done?

kate
  • 113
  • 1
  • 2
  • 11

2 Answers2

1

Make sure you have not output anything to the browser before you call that line, including any white space or line breaks.

avoliva
  • 3,181
  • 5
  • 23
  • 37
0

This error is because the PHP script sent the HTTP headers prior to the session_start()Make sure that you don't send any contents before calling session_start().

Hungry Mind
  • 226
  • 1
  • 4
  • 12
  • Yes, I tried removing all content before block and it worked. Thanks for your reply. – kate Oct 21 '14 at 16:25