Public domain
<?php
session_start();
//////////////////////////////////////////////////
// Configurations
//////////////////////////////////////////////////
$username="USER";
$password="PASS";
$download_dir="Download";
//////////////////////////////////////////////////
echo("<script> history.forward();</script>\n");
echo("<body link=black alink=black vlink=black>");
logout();
login();
if(isset($_POST['url']) && $_POST['url'] != "")
if(is_writable($download_dir))
{
$url=$_POST['url'];
$filename=$url;
while(strpos($filename,"/") !== FALSE && substr($filename,strpos($filename,"/")+1) != "" )
{
$filename=substr($filename,strpos($filename,"/")+1);
}
$filename="$download_dir/$filename";
echo "Downloading <b>$filename</b> from <b>$url</b> . . . ";
if (!$handle = fopen($filename, 'a'))
{
echo "Cannot open ($filename)";
}
else
{
if(fwrite($handle,file_get_contents($url)) === FALSE)
{
echo "Cannot write to ($filename)";
}
else echo "Success";
fclose($handle);
}
}
else echo "<b>$download_dir</b> directory is not writable !!!";
?>
<br>
<form method=post action=''>
Enter URL :
<input type=text name=url>
<input type=submit value=Download>
</form>
<a href=?logout>Logout</a>
<?php
//////////////////////////////////////////////////
// Functions
//////////////////////////////////////////////////
function login()
{
global $username,$password;
if (!isset($_SESSION['admin_is_logged_in']) || $_SESSION['admin_is_logged_in'] !== true)
{
$errorMessage = '';
if (isset($_POST['username']) && isset($_POST['password']))
{
if ($_POST['username'] == "$username" && $_POST['password'] == "$password" )
{
$_SESSION['admin_is_logged_in'] = true;
return;
}
else
{
$errorMessage = 'Sorry, wrong username / password';
}
}
echo "
<center><h2> Login Page </h2></center>
<br>
<form action='' method=post>
<table width=400 border=1 align=center cellpadding=2 cellspacing=2>
<tr>
<td width=150>Username</td>
<td><input name=username type=text></td>
</tr>
<tr>
<td width=150>Password</td>
<td><input name=password type=password></td>
</tr>
<tr>
<td width=150> </td>
<td><input name=login type=submit value=Login></td>
</tr>
</table>
</form>
";
echo "<p align=center><strong><font color=#990000>$errorMessage</font></strong></p>";
exit;
}
}
function logout()
{
if( isset($_SERVER['QUERY_STRING']) &&
$_SERVER['QUERY_STRING'] != "" &&
$_SERVER['QUERY_STRING'] == "logout" )
{
if (isset($_SESSION['admin_is_logged_in']))
{
unset($_SESSION['admin_is_logged_in']);
}
}
}
//////////////////////////////////////////////////
?>
BY: Pejman Moghadam
TAG: php
DATE: 2012-01-18 13:52:39