错误提示: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

原因:      在session_start()之前如果有输出内容,会出错,

解决办法: 在session_start()之前加上ob_start();

index.php



<?php
error_reporting(-1);
ob_start();//不加会出错,无法写入session
register_shutdown_function('close');


echo 1;
 session_start();
 
$_SESSION['password']='mima2ddddddddddddddda2';

function close()
	{
		if(session_id()!=='')
			@session_write_close();
	}
?>
<a href="index2.php" >index2</a>


index2.Php

<?php
error_reporting(-1);
ob_start();//不加会出错,无法读取session
echo 1;
 session_start();

echo $_SESSION['password'];
var_dump($_SESSION);
?>
<a href="index.php" >index</a>

  

相关文章:

  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-09-02
猜你喜欢
  • 2022-12-23
  • 2021-09-04
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案