-2

home screen

Error: ( ! )

enter image description here

Warning: Session_start(): Cannot Send Session Cache Limiter - Headers Already Sent (Output Started At C:\Wamp64\Www\Needheee\Userheader.Php:192) In C:\Wamp64\Www\Needheee\Userheader.Php On Line 193

<li>
        <a> Welcome 
        <?php 
        session_start();
        echo $_SESSION['username'];
        ?>
        </a>
    </li>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98

5 Answers5

2

By default, the PHP sessions feature use a cookie to propagate the session ID between requests.

The cookie is set by session_start(). Because the cookies are sent in the header of the HTTP response, session_start() must be called before any output is sent to the browser.

You call session_start() after some HTML is already generated. You can either move the call to session_start() before anything else in the file of use output buffering to capture the output (instead of sending it to the browser immediately) and send it when it's appropriate for your application's flow.

axiac
  • 68,258
  • 9
  • 99
  • 134
0

Place session_start() at the very beginning of the page

<?php
 session_start();
?>
//html codes

    <li>
            <a> Welcome 
            <?php 

            echo $_SESSION['username'];
            ?>
            </a>
        </li>
affaz
  • 1,191
  • 9
  • 23
0

This means you have too many session_starts. to remove this error, check for a valid session on every page. Do this:

<?php
if(!isset($_SESSION)){
    session_start();
}
//this would check for a session before starting it. if session has started, php would not attempt to start a new one
?>
Rotimi
  • 4,783
  • 4
  • 18
  • 27
0

Cannot Send Session Cache Limiter - Headers Already Sent

This warning is displayed when a text was written (Buffer created) and this can happen when you do a redirect when your script has created some text.

The Solution : move your session_start() function into the top of the file before your script output any text.

G. Mansour
  • 696
  • 6
  • 15
0

Headers Already Sent Error mostly occur when

  1. You have white space in you script at very first line of you script
  2. If you are sending the output of page before executing the php script.

Solution of Error

  1. write you php code first then write html.
  2. place this code at first line <?php ob_start();?>
Aman Maurya
  • 1,305
  • 12
  • 26