私は単純なフォームログインを行っています。多くの失敗を試みた後、どのように機能するかを理解するために例をダウンロードしました。問題は次のとおりです。ログインフォームでデータを送信してコントローラーを呼び出した後、コントローラーで送信されたデータを取得できません。
ユーザー名を印刷するだけの簡単なことを試しましたが、何も得られませんでした。
私は何を間違っていますか?何かを設定する必要がありますか?
別の問題は次のとおりです。通常の HTML フォームを使用してフォームをコーディングすると、フォームがうまく機能します。
ここで見つけたコードを使用しましたhttp://www.codefactorycr.com/login-with-codeigniter-php.html
私はすでに別のコードと自分のコードを使用していますが、atm は何が起こっているのかを理解するためにあらゆることを試みています。
login_view.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple Login with CodeIgniter</title>
</head>
<body>
<h1>Simple Login with CodeIgniter</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('verifylogin'); ?>
<label for="username">Username:</label>
<input type="text" size="20" id="username" name="username"/>
<br/>
<label for="password">Password:</label>
<input type="password" size="20" id="passowrd" name="password"/>
<br/>
<input type="submit" value="Login"/>
</form>
</body>
</html>
verifylogin.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyLogin extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
function index()
{
$username = $this->input->post('username');
echo "Username: " . $username;
//This method will have the credentials validation
$this->load->library('Form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->load->view('login_view');
}
else
{
//Go to private area
redirect('home', 'refresh');
}
}
function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->user->login($username, $password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->id,
'username' => $row->username
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid username or password');
return false;
}
}
}
?>
このユーザー名を書くことさえできません
$username = $this->input->post('username');
echo "Username: " . $username;