pftplogin.phps

<?php
 
  function authenticate() { 
   header('WWW-Authenticate: Basic realm="Secure FTP Login"'); 
   header('HTTP:/1.0 401 Unauthorized');
   echo "Authentication Failed!"; 
         exit(); 
  } 
 
// check for the existence of a value for $PHP_AUTH_USER and display the username/password box if it does
// not exist then exit the script.
  if(!isset($PHP_AUTH_USER)) { 
    authenticate(); 
    exit; 
    echo "Unable to authenticate your username/password. Authorization Failed\n"; 
  } 
 
  else { 
 
$ftp_server="localhost";
 
// set up basic connection
$conn_id = ftp_connect("$ftp_server"); 
 
// login with username and password
// use @ to suppress error messages returned by ftp_login() function because you will be printing 
// your own error messages
$login_result = @ftp_login($conn_id, "$PHP_AUTH_USER", "$PHP_AUTH_PW"); 
 
// check connection
if ((!$conn_id) || (!$login_result)) { 
    authenticate();
        echo "Ftp connection has failed!";
        echo "Attempted to connect to $ftp_server for user $PHP_AUTH_USER"; 
        die; 
    } 
 
// close the FTP stream 
ftp_quit($conn_id);
}
?>