1
填寫表格的代碼(login.php中)的值:PHP文章沒有形式
<?php
if (Input::exists()) {
echo "Input <br/>";
if (Token::check (Input::get ('token'))) {
echo "Token <br/>";
$validate = new Validation();
$validation = $validate->check ($_POST, array (
'username' => array (
'required' => true
),
'password' => array (
'required' => true
)
));
if ($validation->passed()) {
$user = new User();
$remember = (Input::get ('remember') === 'on') ? true : false;
$login = $user->login (Input::get ('username'), Input::get ('password'), $remember);
if ($login) {
Session::flash ('home', 'You are now logged in!');
Redirect::to ('index.php');
} else {
echo '<p>Sorry, logging in failed</p>';
}
} else {
foreach ($validation->errors() as $error) {
echo $error, '<br>';
}
}
}else{
echo "No Token <br/>";
}
}else{
echo "No Input <br/>";
var_dump ($_POST);
}
?>
<br />
<div class="row">
<div class="col-md-4 col-md-offset-4">
<p class="text-center">
Log in or <a href="index.php?page=register.php">Register</a>
</p>
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<label for="username" class="col-sm-2 control-label">Username: </label>
<div class="col-sm-10">
<input type="text" class="form-control" name="username"
id="username" placeholder="Username" autocomplete="off" />
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password: </label>
<div class="col-sm-10">
<input type="password" class="form-control" name="password"
id="password" placeholder="Password" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label> <input type="checkbox" name="remember" id="remember" />
Remember me
</label>
</div>
</div>
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>" />
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-default" value="Log in" />
</div>
</div>
</form>
</div>
而且Input.php:
<?php
class Input{
public static function exists($type = 'post'){
switch($type){
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
public static function get($item){
if(isset($_POST[$item])){
return $_POST[$item];
}elseif(isset($_GET[$item])){
return $_GET[$item];
}
return '';
}
}
?>
我不看看有什麼不對。我檢查了6次,但仍然沒有。 login.php包含在index.php中,但這隻有一個開始html-tag頭部和身體的開始標籤。
有人可以解釋我做錯了什麼。
這不起作用。 –