Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 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 Reply

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...