我正在观看登录和注册页面教程我正在使用闪光灯说用户已成功注册,现在我正在测试重定向到错误页面,而教程中的人员并没有这样做删除闪存代码并且闪存没有显示,并且自定义404错误页面的内容仍然显示,即使我离开闪存并更改回显消息,闪存仍然保持不变旧的还在。
这是闪光灯
Session::flash('home', 'You have been registered and can now login');
即使这行和index.php的内容被删除,它仍然会重定向到index.php
注册码
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array(
'required' => true,
'min' => 6,
'max' => 20,
'unique' => 'users'
),
'password' => array(
'required' => true,
'min' => 6
),
'password_again' => array(
'required' => true,
'matches' => 'password'
),
'name' => array(
'required' => true,
'min' => 2,
'max' => 50
)
));
if($validation->passed()) {
$user = new User();
$salt = Hash::salt(32);
try {
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'name' => Input::get('name'),
'joined' => date('Y-m-d H:i:s'),
'group' => 1
));
Session::flash('home', 'You have been registered and can now login');
Redirect::to(404);
}catch(Exception $e) {
die($e->getMessage());
}
} else {
foreach ($validation->errors() as $error) {
echo $error, '<br>';
};
}
}
}
?>
<form action ="" method= "post">
<div class="field">
<label for= "username">Username</label>
<input type= "text" name= "username" id ="username" value="<?php echo escape(Input::get('username')); ?>" autocomplete="off">
</div>
<div class="field">
<label for="password">Choose a password</label>
<input type="password" name="password" id="password">
<div class="field">
<label for="password_again">Confirm password</label>
<input type="password" name="password_again" id="password_again">
<div class="field">
<label for= "name">Name</label>
<input type= "text" name= "name" value="<?php echo escape(Input::get('name')); ?>" id ="name">
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Register">
</form>
Redirect.php
<?php
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 'includes/errors/404.php';
exit();
break;
}
}
header('Location: ' . $location);
exit();
}
}
}
404.php
this page was not found
答案 0 :(得分:0)
不确定我是否理解正确,但Redirect::to(404);
代码会将您引导至404页面,并包含404.php文件。
删除行Session::flash('home', 'You have been registered and can now login');
或index.php的内容不会阻止这种情况发生。