Home > Article > Backend Development > Why does session_start() report an error after adding the button tag?
If you add the button label to the navigation bar, an error will be reported. If you remove the button label, it will be fine. The error content is as follows
Warning: session_start(): Cannot send session cache limiter - headers already sent
Is it because session_start(); cannot have output before it? So why is there no error in the div in front? And there is an a label in the navigation bar. Why doesn’t it report an error? Instead, after adding the button label, an error occurs?
<code><nav class="navbar navbar-default fix-top" style="background-color: #fff"> <div class="container nav"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse"> <span class="sr-only"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="qq.php">W3Cschool</a> </div> <div class="collapse navbar-collapse" id="navbar" > </div> </div> </nav> <div>aaaaa</div> <?php session_start(); ?></code>
If you add the button label to the navigation bar, an error will be reported. If you remove the button label, it will be fine. The error content is as follows
Warning: session_start(): Cannot send session cache limiter - headers already sent
Is it because session_start(); cannot have output before it? So why is there no error in the div in front? And there is also an a label in the navigation bar. Why does it not report an error? Instead, after adding the button label, an error is reported?
<code><nav class="navbar navbar-default fix-top" style="background-color: #fff"> <div class="container nav"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse"> <span class="sr-only"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="qq.php">W3Cschool</a> </div> <div class="collapse navbar-collapse" id="navbar" > </div> </div> </nav> <div>aaaaa</div> <?php session_start(); ?></code>
Just put session_start()
at the front.
The button will output, but there cannot be any output before the HTTP cookie request, even a blank line.
Put this session_start() at the head of the page
My local version is php5.5, and no error was reported when I used your code