开发者

PHP - loading static class sends headers

I have a simple page in HTML/CSS/PHP that connects to MySQL DB.

"index.php" is loaded and "mainPage::showSectionLogin($_SESSION['login'])" shows logging form

<?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="mai开发者_高级运维n">
      <?php mainPage::showActualNews(5) ?>
    </DIV>
  </BODY>
</HTML>

"login.php" is executed after the logging form was filled

<?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");
} ?>

I don't inderstand why, during logging in, "header("refresh:1;url=index.php");" (line:18) says that "require_once 'clMainPage.php';" in file "login.php" (line:2) sends headers. How is it possible that "require_once 'clMainPage.php';", that is a class declaratin containing only static functions, actually sends headers?


There is white space after your closing php tag on line 1, that's what sends the headers

<?php
session_start();
require_once 'clMainPage.php';
if($_SERVER["REQUEST_METHOD"] == "POST") {


Do you have any whitespace / output before / after your < ?php. This is often the cause.

What does 'clMainPage.php' contain?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜