[英]PHP - loading static class sends headers
我在HTML / CSS / PHP中有一個簡單的頁面可以連接到MySQL DB。
“ index.php”已加載,並且“ mainPage :: showSectionLogin($ _ SESSION ['login'])”顯示記錄表單
<?php session_start(); ?>
<?php require_once 'clMainPage.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
<HEAD>
<?php mainPage::setSectionHEAD() ?>
<LINK rel="stylesheet" type="text/css" href="style.css">
</HEAD>
<BODY>
<DIV id="sidebar">
<?php mainPage::showSectionLogin($_SESSION['login']) ?>
<?php mainPage::showSidebarMenu($_SESSION['login']) ?>
</DIV>
<DIV id="main">
<?php mainPage::showActualNews(5) ?>
</DIV>
</BODY>
</HTML>
填寫日志表單后執行“ login.php”
<?php session_start(); ?>
<?php require_once 'clMainPage.php'; ?>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
$dblink = mainPage::openDBconn();
$result = mainPage::checkIfUserCanLogIn($dblink, $_POST['inpLogin'], $_POST['inpPassw']);
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_array($result);
mainPage::logUserIn($row['login'], $row['passw']);
}
else
{
die("error checking user: there is no such user in a database");
}
mainPage::closeDBconn($dblink);
header("refresh:1;url=index.php");
} ?>
我不理解為什么在登錄過程中會出現“ header(“ refresh:1; url = index.php”);“ (line:18)說“ require_once'clMainPage.php';” 在文件“ login.php”(第2行)中發送標頭。 “ require_once'clMainPage.php';”(僅包含靜態函數的類聲明)實際上如何發送標頭?
在第1行中關閉php標記后有空白,這就是發送標頭的原因
<?php
session_start();
require_once 'clMainPage.php';
if($_SERVER["REQUEST_METHOD"] == "POST") {
您的< ?php
之前/之后是否有空格/輸出< ?php
這通常是原因。
“ clMainPage.php”包含什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.