PDO を使用するように記述されていることがわかった関数があり、codeigniters アクティブ レコード db クラスを使用するように変更しました。次のように関数内にコードを配置すると、すべてが機能します。
function login_attempt_count() {
$seconds = 10;
// First we delete old attempts from the table
$oldest1 = strtotime(date('Y-m-d H:i:s').' - '.$seconds.' seconds');
$oldest2 = date('Y-m-d H:i:s',$oldest1);
$del_data = $oldest2;
$this->db->where('when <', $del_data);
$this->db->delete('Login_Attempts');
// Next we insert this attempt into the table
$data = array(
'ip' => $_SERVER['REMOTE_ADDR'],
'when' => date("Y-m-d H:i:s"));
$this->db->insert('Login_Attempts', $data);
// Finally we count the number of recent attempts from this ip address
$count = 'SELECT count(*) as number FROM Login_Attempts WHERE ip = ?';
$num = $this->db->query($count, $_SERVER['REMOTE_ADDR']);
if ($num->num_rows() > 0){
foreach($num->result() as $attempt){
$attempts = $attempt->number;
return $attempts;
}
}
}
次のように使用します。
$max_attempts = 3;
if(login_attempt_count() <= $max_attempts) {
echo 'login';
}else{
echo 'To many attempts';
}
またはこれ:
$a = login_attempt_count();
ページの残りの部分が読み込まれないようにします。したがって、これはエラーを示します。繰り返しますが、関数内で関数の外でコードを使用すると、期待どおりに機能します。
または、私が使用すべき完全に優れた安全な方法がある場合は、提案をお待ちしています. ありがとう!