Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

php - DOCTYPE in the head of the page causes session_problem

i had this error in my site:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - 
headers already sent (output started at /home/rentedco/public_html/try6.php:2) in 
/home/rentedco/public_html/try6.php on line 2

i have created a simple php file containing only the beggining of the other pages:

<!DOCTYPE html>
<?php session_start();
echo 'fsdf';
?>

and i discovered that if i remove the DOCTYPE i dont get this problem anymore, my problem is that i dont want to ruin something else by removing this header. can i remove it? can i pt it after the session_start call?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yeah, putting the doctype out there pushes data onto the PHP output buffer, but the session_start() requires writing cookie data to the header. The doctype is part of the HTML page, and not the header, so it should be safe to put it in after the session_start().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...