Warning: session_start () [function.session-start]: Unable to send session cache limiter

I have a problem with Session_start () here:

Warning : session_start () [function.session-start]: cannot send session cache limiter - headers already sent (output starts from C: \ xampp \ htdocs \ pages \ home.php: 4) to C: \ xampp \ htdocs \ charts \ home-chart.php on line 2

and in home-chart.php in line 2 I wrote these codes:

session_start(); . . . echo ' username: '.$_SESSION['user_name']; 

although with this warning I can get the result of $_SESSION['user_name'] , but when I try to clear this part of the code:

 session_start(); 

I do not see the result on the screen. so what's your solution?

 <?php @session_start(); require_once '../class/chart.class.php'; $chart = new chart(); ?> <html> <head> <link href='../css/home-chart.css' rel='stylesheet' type='text/css' /> </head> <body> <div class='float_left' style="margin-bottom:20px;"> <div class='float_left' style='line-height: 9.41px; font-size: x-small;'>0<br /></div> <div class='float_left' style="background-image: url('../image/web/chart.png'); width: 367px; height: 226px; " > <!-- 1 --><div class='float_left float_left column' style='margin-left:2px;'> <?php echo $chart->mysql_fetch($chart->daycal(-3)); ?> </div> <!-- 2 --><div class='float_left float_left column'> <?php echo $chart->mysql_fetch($chart->daycal(-2)); ?> </div> <!-- 3 --><div class='float_left column' > <?php echo $chart->mysql_fetch($chart->daycal(-1)); ?> </div> <!-- 4 --><div class='float_left column' > <?php echo $chart->mysql_fetch($chart->daycal(0)); ?> </div> <!-- 5 --><div class='float_left column' > <?php echo $chart->mysql_fetch($chart->daycal(1)); ?> </div> <!-- 6 --><div class='float_left column' > <?php echo $chart->mysql_fetch($chart->daycal(2)); ?> </div> <!-- 7 --><div class='float_left column' > <?php echo $chart->mysql_fetch($chart->daycal(3)); ?> </div> </div> <div class='float_single_full' ></div> <div class='float_left bottom_chart' style="margin-left:10px;"><?php echo $chart->dayofweek(-3); ?></div> <div class='float_left bottom_chart'><?php echo $chart->dayofweek(-2); ?></div> <div class='float_left bottom_chart'><?php echo $chart->dayofweek(-1); ?></div> <div class='float_left bottom_chart' style='font-weight:bold'><?php echo $chart->dayofweek(0); ?></div> <div class='float_left bottom_chart'><?php echo $chart->dayofweek(1); ?></div> <div class='float_left bottom_chart'><?php echo $chart->dayofweek(2); ?></div> <div class='float_left bottom_chart'><?php echo $chart->dayofweek(3); echo ' username: ' . $_SESSION['user_name']; ?></div> </div> </body> </html> 
+6
source share
8 answers

Even if you have empty lines before the <?php tag, you cannot set headers. Your start of the file with line numbers should look like this:

 1. <?php 2. session_start(); 3. header('Cache-control: private'); 

The message says "headers sent on line 2", so you output something (space, blank line, etc.) in line 4 home.php

If this file is include, you should put your session_start(); to the beginning of home.php, and then it is not needed in this file.

+13
source

This means that you printed something before calling session_start ().

You should not print anything before session_start ().

The error message assumes that you first printed something in C: \ xampp \ htdocs \ pages \ home.php on line 4.

+3
source

write this code before the head tag. as below:

 <?php ob_start(); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php session_start(); ?> </body> 
+3
source
  • Open php.ini file ,
  • Changes session.auto_start = 0 to session.auto_start = 1
  • Restart apache service.
+2
source

If all of the above answers did not work for you:

Some editors, saving the file as UTF-8, insert extra characters into the file at the very beginning (the format does not require it, but it is all the same). Then refuse to show you these characters when they display the file. To find out if your editor is one of them, try saving an empty file and see how many bytes it takes. If it is greater than zero (maybe three), then you have to say that your editor stops messing around (and how you do it depends on the editor).

This does not happen if you save the file as ANSI.

+1
source

Try inserting <?php ob_start(); ?> <?php ob_start(); ?> at the top of the page. He will work like magic.

+1
source

I also ran into the same problem and resolved this by writing below code at the top of the php page:

 <?php session_start(); ?> 
+1
source

Use

 session_cache_limiter(FALSE); 

before

 session_start(); 

This will help you :)

0
source

Source: https://habr.com/ru/post/897053/


All Articles