页面头部的 DOCTYPE 导致 session_problem [英] DOCTYPE in the head of the page causes session_problem

查看:47
本文介绍了页面头部的 DOCTYPE 导致 session_problem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站出现此错误:

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

我创建了一个简单的 php 文件,只包含其他页面的开头:

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

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

并且我发现如果我删除 DOCTYPE 我不会再遇到这个问题,我的问题是我不想通过删除这个标题来破坏其他东西.我可以删除它吗?我可以在 session_start 调用后使用它吗?

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?

推荐答案

是的,将 doctype 放在那里会将数据推送到 PHP 输出缓冲区,但 session_start() 需要将 cookie 数据写入标头.doctype 是 HTML 页面的一部分,而不是标题,因此将其放在 session_start() 之后应该是安全的.

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

这篇关于页面头部的 DOCTYPE 导致 session_problem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆