4

I have got a PHP script. In this script I will be connected to a FTP server, and show a file. What would be the best way to secure this script so can only log in 5 times in 1 hour or something like that?

My script:

<?php
session_start();

$_SESSION["ftp_user"] = $_POST["user"];    
$_SESSION["ftp_pass"] = $_POST["pass"];
$ftp_pass = $_POST["pass"];
$ftp_server = "ftp.guusvanwalstijn.nl";

function test()    
{ 
echo "Do whatever i want";
}


// Verbinding maken
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 


// Error die je krijgt als je het wachtwoord verkeerd hebt ingetypt
function error_while_connecting() {
echo "Error while connecting to the server";
echo "<br />Probably the password is wrong or the server is offline";
}

// Inloggen met de gegeven inloggegevens
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    test();

} else {
    error_while_connecting();
    print("<br />Debug: " . $_POST["pass"] . "<br />");
    print("<br />Debug: " . $_POST["user"] . "<br />");
}

ftp_close($conn_id);
?>
4

1 回答 1

5

您可以将日志表(时间戳)添加到数据库或将其存储在文件中。从中获取最后 5 条记录,并检查最旧的记录是否超过 1 小时。如果是,那么您可以允许连接到数据库。如果不是,则拒绝,因为已达到限制。您还可以定期清除此文件/数据库表的内容,以避免增长过多。

于 2013-11-05T08:34:01.347 回答