在doctype之前PHP包含(),导致空格
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在doctype之前PHP包含(),导致空格,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3226字,纯文字阅读大概需要5分钟。
内容图文
我有一个有空白问题的网站.我在doctype之前包含了一些文件
这导致输出空白区域.
搜索后我找到了这个解决方案:
Problem with whitespace before doctype
但是在删除后?>我仍然遇到问题.以下是代码:
<?php
include ("include/session.php");
include ("include/updatestage.php");
?>
<!DOCTYPE HTML>....
这是session.php:
<?php session_start();
// if a team name has been assigned to a session...
if ( isset($_SESSION ['teamName']))
{
//create "global variable $teamName that can be used across all pages as long as the function "session_start(); is present"
$teamName = $_SESSION ['teamName'];
}
else{
die ( "You are not logged in! Redirecting to login page...<meta http-equiv='REFRESH' content='2; url = index.php'>");
}
这是updatestage.php:
<?php
include("config.php");
//update stage
$inserted="n";
mysql_query ("UPDATE `team` SET `inserted`='$inserted' WHERE teamName = '$teamName' ");
$advance="n";
mysql_query ("UPDATE `game` SET `advance`='$advance' ");
这是getstageinfo.php:
<?php
include("include/config.php");
//Select the slogan from the current user
$currentStage = mysql_query("
SELECT `currentStage` FROM `team` WHERE `teamName` = '$teamName'
");
//assign the text located at the logo field (the path of the logo) to a variable $slogan
$row = mysql_fetch_assoc($currentStage);
$currentStage= $row['currentStage'];
?>
最后这里是config.php:
<?php
// connect to database
$con = mysql_connect("xxxxxxx","xxxxxxx","xxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// select database
mysql_select_db ("xxxxxxx");
?>
////////////////////////////////////////////////// ////////////////////////////////////////
好的,我已经加入了?>并尝试了以下建议:
<!DOCTYPE HTML>
<?php
include("include/session.php");
include("include/updatestage.php");
?>
或尝试:
<?php
echo "<!DOCTYPE HTML>\n";
include ("include/session.php");
include ("include/updatestage.php");
?>
生产:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at public_html/period1.php:2) in public_html/include/session.php on line 1
试:
<?php
include("include/session.php");
include("include/updatestage.php");
?><!DOCTYPE HTML>
要么:
<?php
ob_start();
echo "<!DOCTYPE HTML>\n";
include ("include/session.php");
include ("include/updatestage.php");
ob_end_flush();
?>
仍然产生白色空间.
解决方法:
您可以像这样解决问题:
<?php
include ("include/session.php");
include ("include/updatestage.php");
?><!DOCTYPE HTML>
但是我已经观察到了这方面的错误行为(虽然不是自PHP4以来),因此保证修复的最简单的解决方案是放置<!DOCTYPE>在包含之前 – 因为既没有包含文件也没有输出任何内容,如果有的话会破坏你的文档.
<!DOCTYPE HTML>
<?php
include ("include/session.php");
include ("include/updatestage.php");
?>
<!-- Rest of HTML -->
或这个:
<?php
echo "<!DOCTYPE HTML>\n";
include ("include/session.php");
include ("include/updatestage.php");
?>
<!-- Rest of HTML -->
记得要确保<在开头<?php标签是所有文件中的第一个字符,如果你选择第二个选项. 编辑首先完全没有考虑到已经养成丑陋头脑的会话/ cookie问题,这是一个有效的解决方案:
<?php
ob_start();
echo "<!DOCTYPE HTML>\n";
include ("include/session.php");
include ("include/updatestage.php");
ob_end_flush();
?>
<!-- Rest of HTML -->
内容总结
以上是互联网集市为您收集整理的在doctype之前PHP包含(),导致空格全部内容,希望文章能够帮你解决在doctype之前PHP包含(),导致空格所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。