개발

[php] Cannot send session cache limiter - headers already sent

지승준 2014. 11. 25. 12:51

php 에서 SESSION(세션) 을 사용할때에 


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at ~~~)


위와 같은 에러가 뜨는데, 위 에러가 뜨는 경우는 크게 2가지가 있습니다.

첫번째로는 

1
2
3
4
<? 
 
session_start();
?>
cs


위 처럼, session_start(); 코드가 해당 php(html 문서내) 가장 최상단에 위치하지 않는 경우가 있다.

위 같은 경우에는 php코드를

1
2
3
<? 
session_start();
?>
cs


위와 같이 변경해주면 정상적으로 작동되고, 

또 다른 하나는 에디터 자체에서 자동으로 인코딩이 설정되있어서 발생합니다.

이런경우에는 notepad++ 기준으로 

인코등을 UTF-8(BOM 없음) 으로 설정해주시고, 한글이 깨지실 경우

head 태그 내에 meta 태그로 

1
2
3
4
5
6
7
<html>
  <head
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">    
  </head
  <body>    
  </body>
</html>
cs


위와 같이 설정해 주시면 됩니다.


http://ambitiousdh.tistory.com/entry/php-Cannot-send-session-cache-limiter-headers-already-sent

http://cybercafe.tistory.com/178