简体   繁体   English

为什么在doctype上方有PHP代码?

[英]Why do I have PHP code above the doctype?

I'm still learning this stuff, but for the most part, my understanding is that you want code in the head or the body. 我仍在学习这些东西,但是在大多数情况下,我的理解是您希望头部或身体中的代码。 I'm working with a page that is a login page. 我正在使用作为登录页面的页面。

Above the doctype is all the php code for the login validation checking and the "root.php" include which is declaring the root of the project, etc. 在doctype上方是用于登录验证检查的所有php代码,其中的“ root.php”包括用于声明项目的根目录等。

Is this the way things should be done? 这是应该做的事情吗?

If I move the doctype to the top, I get an error. 如果我将文档类型移到顶部,则会出现错误。 As it is, the browser sees the doctype as the top item when I view source. 照原样,当我查看源代码时,浏览器将doctype作为头条。

So my question is when would I want to put code above the doctype? 所以我的问题是我什么时候要将代码放在doctype之上?

标头需要在第一个html输出之前发送,因此,例如,如果要使用session_start(),则需要在发送第一个文本之前发送。

为什么我要申报<!--?php</div--><div id="text_translate"><p> 我认为我已经习惯了关于项目中 PHP 声明的相当宽松的政策 - 我一直只是使用:</p><pre> <? // here is my php code?></pre><p> 我刚刚在 FastCGI 下使用 PHP-FPM 设置了一个 nginx 服务器,现在它需要我明确声明:</p><pre> <?php // here is my php code?></pre><p> 有什么办法可以改变吗? (否则我将不得不 go 进入我的项目并查找/替换所有发生这种情况的实例)。</p></div> - Why do I have to declare <?php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要在带有html的php文件中使用!DOCTYPE声明吗? - Do I need a !DOCTYPE declaration in a php file with html? 为什么我要申报<!--?php</div--><div id="text_translate"><p> 我认为我已经习惯了关于项目中 PHP 声明的相当宽松的政策 - 我一直只是使用:</p><pre> <? // here is my php code?></pre><p> 我刚刚在 FastCGI 下使用 PHP-FPM 设置了一个 nginx 服务器,现在它需要我明确声明:</p><pre> <?php // here is my php code?></pre><p> 有什么办法可以改变吗? (否则我将不得不 go 进入我的项目并查找/替换所有发生这种情况的实例)。</p></div> - Why do I have to declare <?php xsl中doctype之前的PHP代码 - PHP code before doctype in xsl 当我在 php 代码中没有错误时,为什么我的表是空的? - why my table is empty when i have no error in php code? 我是否必须将SSL证书集成到我的PHP代码中? - Do i have to integrate my SSL certificate into my PHP code? 我是否需要为php代码块更改服务器的任何设置? - Do I have to change any settings of server for php code blocks? PHP命名空间资格 - 为什么我必须完全符合资格? - PHP Namespace qualification - why do I have to fully qualify? 为什么我的PHP循环不起作用? 还是我必须添加“如果”? - Why my PHP loop does not work? Or do I have to add 'if'? 为什么在PHP和JSON中有不同的转储? - Why do I have different dump in PHP and JSON? 为什么在PHP中执行if代码时会得到一个值 - Why is that when I do an if code in PHP i get a value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM