Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\server\basic\lib_tmp\test.php:2) in D:\server\basic\lib_tmp\test.php on line 3
hoặc
Warning: Cannot modify header information - headers already sent by (output started at D:\server\basic\lib_tmp\test.php:2) in D:\server\basic\lib_tmp\test.php on line 3
- Lý do: hàm session_start() và header() chỉ được thực hiện khi trước đó không có 1 byte dữ liệu nào được sent đế trình duyệt.
Câu báo lỗi trên cho biết có 1 byte dữ liệu nào đó ở dòng 2 của file D:\server\basic\lib_tmp\test.php (output started at D:\server\basic\lib_tmp\test.php:2)
cách khắc phục:
- thủ công: dò đến dòng co byte được sent (output started at D:\server\basic\lib_tmp\test.php:2) và bỏ hết các phần dữ liệu được sent
- dùng ob_clean() trước session_start() hoặc header() để xóa hết các ký tự đã sent
chú ý: file php như sau sẽ bị lỗi khi dùng session_start() hoặc header()
<?php
session_start();
?>
lý do: có 1 ký tự \n (enter) nằm ngoài cặp <?php .. ?>
cách sửa:
<?php
session_start();
?>