![](/img/trans.png)
[英].htaccess file issue while redirecting from index.php to normal link when on home page
[英]Not redirecting to home page (index.php)
我的代码有问题吗? 它可以工作,但它不会重定向到我的index.php,它始终以表单所在的login.php结尾。
<?php
include 'core/ini.php';
if (empty($_POST) === false) {
$username = $_POST ['username'];
$password = $_POST ['password'];
if (empty ($username) === true || empty ($password) === true ) {
$errors[] = 'You need to enter a username and password!';
} else if (user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) === false) {
$errors[] = 'You haven\'t activated your account! ';
} else {
$login = login($username, $password) ;
if ($login === false) {
$errors[] = 'That username/password combination is incorrect ';
} else {
$_SESSION['user_id'] = $login;
header('Location :index.php');
exit();
}
}
print_r($errors);
}
?>
thanks!
EDIT *
this is my login.php
<?php
include 'core/ini.php';
if (empty($_POST) === false) {
$username = $_POST ['username'];
$password = $_POST ['password'];
if (empty ($username) === true || empty ($password) === true ) {
$errors[] = 'You need to enter a username and password!';
} else if (user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) === false) {
$errors[] = 'You haven\'t activated your account! ';
} else {
$login = login($username, $password) ;
if ($login === false) {
$errors[] = 'That username/password combination is incorrect ';
} else {
$_SESSION['user_id'] = $login;
header('Location :index.php');
exit();
}
}
print_r($errors);
}
?>
这就是流程的去向。 我不知道我应该在哪里开始我的会议,但我不知道为什么它不会出错。
我想你错过了session_start();
由于您正在存储会话,因此位于页面顶部。 启动session_start();
。
您的login()
函数也返回TRUE吗? 回声检查功能是否按预期返回TRUE。
您必须在页面顶部使用session_start
,我认为应该在标头定位后删除exit
。
更改header('Location :index.php');
到header('Location: index.php');
该空间可能是原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.