0

我有以下代码,但我在这里被阻止了..

<?php
require 'members/core/init.php';
$general->logged_in_protect();

if (empty($_POST) === false) {

$username = trim($_POST['username']);
$password = trim($_POST['password']);

if (empty($username) === true || empty($password) === true) {
    $errors[] = 'Sorry, but we need your username and password.';
} else if ($users->user_exists($username) === false) {
    $errors[] = 'Sorry that username doesn\'t exists.';
} else if ($users->email_confirmed($username) === false) {
    $errors[] = 'Sorry, but you need to activate your account. 
                 Please check your email.';
} else {
    if (strlen($password) > 18) {
        $errors[] = 'The password should be less than 18 characters, without spacing.';
    }
    $login = $users->login($username, $password);
    if ($login === false) {
        $errors[] = 'Sorry, that username/password is invalid';
    }else {
        session_regenerate_id(true);// destroying the old session id and creating a new one
        $_SESSION['id'] =  $login;
        header('Location: http://www.site.ro/1/index.html');
        exit();
    }
}
} 
?>

以及以下内容:

<?php if ($page == 'login'): ?>
<?php endif; ?>

有人可以帮我组合那部分代码吗?

我试过了,但告诉我标头已经发送..

<?php if ($page == 'login'): ?>
<?php
require 'members/core/init.php';
$general->logged_in_protect();

if (empty($_POST) === false) {

$username = trim($_POST['username']);
$password = trim($_POST['password']);

if (empty($username) === true || empty($password) === true) {
    $errors[] = 'Sorry, but we need your username and password.';
} else if ($users->user_exists($username) === false) {
    $errors[] = 'Sorry that username doesn\'t exists.';
} else if ($users->email_confirmed($username) === false) {
    $errors[] = 'Sorry, but you need to activate your account. 
                 Please check your email.';
} else {
    if (strlen($password) > 18) {
        $errors[] = 'The password should be less than 18 characters, without spacing.';
    }
    $login = $users->login($username, $password);
    if ($login === false) {
        $errors[] = 'Sorry, that username/password is invalid';
    }else {
        session_regenerate_id(true);// destroying the old session id and creating a new one
        $_SESSION['id'] =  $login;
        header('Location: http://www.site.ro/1/index.html');
        exit();
    }
}
} 
?>
<?php endif; ?>

我是 php 的初学者,所以请理解我。先感谢您。

解决 !

这是最终的代码:

<?php if ($page == 'login'):
require 'members/core/init.php';
$general->logged_in_protect();

if (empty($_POST) === false) {

$username = trim($_POST['username']);
$password = trim($_POST['password']);

if (empty($username) === true || empty($password) === true) {
    $errors[] = 'Sorry, but we need your username and password.';
} else if ($users->user_exists($username) === false) {
    $errors[] = 'Sorry that username doesn\'t exists.';
} else if ($users->email_confirmed($username) === false) {
    $errors[] = 'Sorry, but you need to activate your account. 
                 Please check your email.';
} else {
    if (strlen($password) > 18) {
        $errors[] = 'The password should be less than 18 characters, without spacing.';
    }
    $login = $users->login($username, $password);
    if ($login === false) {
        $errors[] = 'Sorry, that username/password is invalid';
    }else {
        session_regenerate_id(true);// destroying the old session id and creating a new one
        $_SESSION['id'] =  $login;
        header('Location: http://www.site.ro/1/index.html');
        exit();
    }
}
} 
endif; ?>
4

2 回答 2

2

一旦任何内容发送给用户,您就不能修改标题。这包括任何错误的空格或换行符。

<?php if ($page == 'login'): ?>
<?php
require 'members/core/init.php';
$general->logged_in_protect();

您停止 php 执行的时间足够长,以便在第 1 行和第 2 行之间发送一个换行符。

将其更改为以下内容,然后重试。

<?php if ($page == 'login'):

require 'members/core/init.php';
$general->logged_in_protect();
于 2013-11-04T17:59:35.887 回答
0

您的代码中的某处可能有一些空格。

  1. 你可以找到它。

  2. 或者最简单的解决方案是打开输出缓冲

输出缓冲允许您做的是回显/打印您想要的任何内容,并且仍然保持在页面中的任何位置发送标题信息的能力。

于 2013-11-04T18:02:08.450 回答