|
|
|
First you need to create a file called ftplogin.php. Note in order to run this
script you must
have an ftp server with a valid account.
Paste the following in ftplogin.php
-------------------------------------------------------------------------------------
----
<?
function checkftplogin($server, $user, $pass) {
$sck = fsockopen($server, 21);
if ($sck) {
$data = fgets($sck, 1024);
fputs($sck, "USER $user\n");
$data = fgets($sck, 1024);
fputs($sck, "PASS $pass\n");
$data = fgets($sck, 1024);
if (ereg("230", $data)) {
# User logged in
return 1;
} else {
# Login failed
return 0;
}
fclose($sck);
} else {
return 0;
}
}
function authenticate() {
Header("WWW-Authenticate: Basic realm=\"Secure Login\"");
echo "Authentication Failed!";
exit();
}
if(!isset($PHP_AUTH_USER)) {
authenticate();
exit;
echo "Authorisation Failed\n";
} else {
$tmp = checkftplogin("localhost", "$PHP_AUTH_USER", "$PHP_AUTH_PW");
if ($tmp != "1") {
authenticate();
}
}
?>
-------------------------------------------------------------------------------------
---------
Now you should have a file called ftplogin.php with a few lines of code.
Go to the bottom of the script and look for the line that starts with $tmp. You
should see
localhost. This is where you enter your ftp server address. You shouldn't have to
edit anything
else. Now if you want to password a file such as index.php then just paste the
following code
at the top of the file.
------------------------------
<?include"ftplogin.php";?>
------------------------------
Now you should be able to view your index.php and have it pop up the user name and
password box. Enter your user name and password of the account you own on the ftp
server.
It should display your index.php if authenticated.
Here is a index.php sample.
----------------------------------
<?include"ftplogin.php";?>
<html>
<center>Hello there Welcome</center>
</html>
----------------------------------
This should work with any ftp server as long as you have an account and the
webserver's ip is allowed to the ftp server's ip address.
John L. Jolly III
john@flaccess.com
www.flaccess.com
|
|
| uaa Categories : Apache, Apache, Browsers, Calendar | | | Check if a file exists on a remote FTP server with PHP Categories : PHP, FTP, Regexps | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | open source online php shop project ecommerce commerce Categories : PHP, Ecommerce | | | ECHO-Java Class Credit Card and Check / ACH Transaction Processor Categories : Java, Cybercash, Classes and Objects, Ecommerce, Java Servlets | | | Why do i get a "Save As" dialog box when I type in the url of a php3 file Categories : PHP Configuration, PHP, Apache, Web Servers | | | Add a linux user from php Categories : Linux, PHP | | | accept_connect -- Accepts a connection on a socket Categories : PHP, PHP Functions, Sockets | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | PHPCatalog Categories : Ecommerce, PHP, Complete Programs | | | Amazon book cover handling Categories : HTML and PHP, PHP, MySQL, Ecommerce | | | PostgreSQL and apache web authentication source.
Categories : Authentication, PostgreSQL, Apache, Web Servers | | | gpg encryption. 99% of it will apply to PGP.
Categories : Credit Cards, Authentication, Ecommerce, Misc | |
|
|
|