私はログインを抑制するためのこの関数を持っていますが、問題があり、関数内でpdo接続が機能しない場合は、 "undefined $ conn"私はそれが範囲に起因する正しい場合、nullの関数 "、これの周りには何か問題がありますか?pdo接続がPHP関数で動作していません
<?php
function check(){
function get_multiple_rows($getfailed) {
$rows = array();
while($row = $getfailed->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $row;
}
return $rows;
}
$throttle = array(1 => 1, 5 => 2, 30 => 10);
if ($getfailed = $conn->query("SELECT MAX(attempted) AS attempted FROM failed_logins")){
$rows = get_multiple_rows($getfailed);
$getfailed->closeCursor();
$latest_attempt = (int) date('U', strtotime($rows[0]['attempted']));
if ($getfailed = $conn->query("SELECT COUNT(1) AS failed FROM failed_logins WHERE attempted > DATE_SUB(NOW(), INTERVAL 15 minute)")){
$rows = get_multiple_rows($getfailed);
$getfailed->closeCursor();
$failed_attempts = (int) $rows[0]['failed'];
krsort($throttle);
foreach ($throttle as $attempts => $delay){
if ($failed_attempts > $attempts) {
$remaining_delay = (time() - $latest_attempt) - $delay;
if ($remaining_delay < 0){
echo "You have exceeded the login attempts limit";
}
return false;
break;
}else{
return true;
}
}
}
}
}
?>
$ connはどこで初期化されていますか?他のファイル?属性として設定できるクラスはありますか? –
[PDO例外](http://php.net/manual/en/pdo.error-handling.php)をオンにすると、エラーがより明らかになります。 – tadman
@ Sergi Case、はいそれは別のファイルであり、クラスにあります – Serjio