Home > Backend Development > PHP Tutorial > Why does session_start() report an error after adding the button tag?

Why does session_start() report an error after adding the button tag?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:19:47
Original
1333 people have browsed it

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>
Copy after login
Copy after login

Reply content:

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>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template