【问题标题】:Warning: Cannot modify header information - headers already sent by (output started at [duplicate]警告:无法修改标头信息 - 标头已由(输出开始于 [重复]
【发布时间】:2014-07-04 14:13:42
【问题描述】:

当我在本地主机上测试我的网站时,一切正常。但是当我在我的网络服务器上测试它时,它总是会出现这个错误:

警告:无法修改标头信息 - 第 14 行 /users/asdasd/www/classes/Redirect.php 中的标头已由(输出开始于 /users/evernet/www/classes/DB.php:139)发送

   class Redirect {
    public static function to($location = null) {
        if($location) {
            if(is_numeric($location)) {
                switch($location) {
                    case 404:
                        header('HTTP/1.0 404 Not Found');
                        include 'inc/errors/404.php';
                        exit();
                    break;
                }
            }
            header('Location: ' . $location);
            exit();
        }
    }
}

-

require_once 'core/init.php';

$user = new User();
if($user->isLoggedIn()) {
    Redirect::to('index.php');
}

if(input::exists()) {
    if(Token::check(Input::get('token'))) {

        $validate = new Validate();
        $validation = $validate->check($_POST, array(
            'username' => array('required' => true),
            'password' => array('required' => true) 
        ));

        if($validation->passed()) {
            $user = new User();
            $login = $user->login(Input::get('username'), Input::get('password'));

            if($login) {
                Redirect::to('admin.php');
            }else {
                echo '<p>Sorry, logging in failed.</p>';
            }

        }else {
            foreach ($validation->errors() as $error) {
                echo $error, '<br />';
            }
        }
    }
}

.

【问题讨论】:

    标签: php header tags


    【解决方案1】:

    在 /users/evernet/www/classes/DB.php:139 行,您正在输出一些文本。

    大概是这样的:

    <?php
    //some code
    ?> <------ A space or newline here
    

    尝试删除 ?> 如果是这样,您正在第 139 行查找 /users/evernet/www/classes/DB.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 2010-12-27
      • 2013-07-09
      • 2017-11-05
      • 2012-02-28
      相关资源
      最近更新 更多