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);
?>