我有以下代码,但我在这里被阻止..
<?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; ?>
答案 0 :(得分: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();
答案 1 :(得分:0)
您的代码中可能有某些空格。
你可以找到它。
或者最简单的解决方法是启用output buffering
您可以使用什么输出缓冲来回显/打印您想要的任何内容,并且仍然能够在页面的任何位置发送标题信息。