I'm creating my own admin panel for managing my download links and keeping track of how many times each one has been downloaded.
I have two log files
download.lnk - stores the url of the file and the name of it
download.log - stores the url of the file and number of times it's been accessed.
download.php is the main script
To download the file, simply use this method
download.php?file=NAME_OF_FILE
The script will search the $file and return the header to download the link that matches the NAME_OF_FILE
to access the admin, simple go to download.php?action=admin. Login from there to go to the main panel were you can view and delete the log file. you can also add, edit, view, remove the links in the download.lnk file.
The problem is, how can add, remove, edit, view the names and urls in the download.lnk when using strings like ?action=admin...etc
Here is the script...
newdreamdesigns.com/download.php
you can kinda figure out what i'm doing...
Here is the code...
<?
// URL of download.php
$dl_url = 'http://newdreamdesigns.com/download.php';
// Path to download.lnk
$dl_lnk = 'download.lnk';
// Path to download.log
$dl_log = 'download.log';
// Username to view logs
$dl_user = 'username';
// Password to view logs
$dl_pass = 'password';
/*****************************************************************************/
/**** Main Program ****/
/*****************************************************************************/
$refr = getenv("HTTP_REFERER");
$addr = getenv("REMOTE_ADDR");
$bwsr = getenv("HTTP_USER_AGENT");
$date = date("F d, Y");
$time = date("g:i:s A");
if ($action == "admin"){
if ($un == "$dl_user" & $pw == "$dl_pass") {
admin($dl_url,$un,$pw,$date);
if ($link == "add") {
add_link($dl_url,$un,$pw);
} elseif ($link == "edit") {
edit_link($dl_url,$un,$pw);
} elseif ($link == "view") {
view_link($dl_url,$un,$pw);
} elseif ($link == "remove") {
remove_link($dl_url,$un,$pw);
} elseif ($log == "view") {
view_log($dl_url,$un,$pw);
} elseif ($log == "remove") {
remove_log($dl_url,$un,$pw);
}
} else {
nopass($dl_url);
}
} else {
main($dl_url);
}
// if login passed...
function admin($dl_url,$un,$pw,$date) {
?>
<head>
<title>Download_PHP Admin v1.0</title>
</head>
<body>
<center><b><font size="3" face="arial">Download_PHP Admin v1.0</font></b></center>
<center>Welcome, <?echo $un; ?>. Today is <?echo $date; ?>.</center>
<br><br>
<center>Links [ <a href="?action=admin&un=<?echo $un; ?>&pw=<?echo $pw; ?>&link=add">Add</a> | <a href="<?echo $dl_url; ?>?action=admin&un=<?echo $un; ?>&pw=<?echo $pw; ?>&link=edit">Edit</a> | <a href="<?echo $dl_url; ?>?action=admin&un=<?echo $un; ?>&pw=<?echo $pw; ?>&link=view">View</a> | <a href="<?echo $dl_url; ?>?action=admin&un=<?echo $un; ?>&pw=<?echo $pw; ?>&link=remove">Remove</a> ]</center>
<center>Logs [ <a href="<?echo $dl_url; ?>?action=admin&un=<?echo $un; ?>&pw=<?echo $pw; ?>&log=view">View</a> | <a href="<?echo $dl_url; ?>?action=admin&un=<?echo $un; ?>&pw=<?echo $pw; ?>&log=remove">Remove</a> ]</center>
<?echo $nofile; ?>
</body>
<?
}
// If login failed...
function nopass($dl_url) {
?>
<head>
<title>Please login</title>
</head>
<body>
<center><b><font size="3" face="arial">Download_PHP Admin v1.0</font></b></center>
<br><br>
<b>Please login</b>
<br>
<form method="get" action="<?print $dl_url; ?>">
<input type="hidden" name="action" value="admin">
Username: <input type="text" name="un" value=""><br>
Password: <input type="text" name="pw" value=""><br>
<input type="submit" value="Login!">
</form>
</body>
<?
}
// Add link
function add_link($dl_url,$un,$pw) {
?>
<br><br>
<center><b>Add Download Link</b></center>
<form method="get" action="<?print $dl_url; ?>">
<input type="hidden" name="action" value="admin">
<input type="hidden" name="un" value="<?echo $un; ?>">
<input type="hidden" name="pw" value="<?echo $pw; ?>">
<input type="hidden" name="link" value="add">
<br>
URL: <input type="text" name="add_link_url" value="http://">
<br>
File Name: <input type="text" name="add_link_name" value="">
<br>
<input type="submit" value="Add Link">
</form>
<br><br>
<?
}
// Edit link
function edit_link($dl_url) {
?>
edit link
<?
}
// View link
function view_link($dl_url) {
?>
view link
<?
}
// Remove link
function remove_link($dl_url) {
?>
remove link
<?
}
// View log
function view_log($dl_url) {
?>
view log
<?
}
// Remove log
function remove_log($dl_url) {
?>
remove log
<?
}
// Unknown
function unknown($dl_url) {
?>
unkown call
<?
}
// Main screen
function main($dl_url) {
?>
<head>
<title>Download_PHP v1.0</title>
</head>
<body>
<center><b><font size="3" face="arial">Download_PHP Admin v1.0</font></b></center>
<br><br>
<b><a href="<?print $dl_url; ?>?action=admin">login</a></b>
<br>
<br><br>
this script created by me
</body>
<?
}
// add the link to the file on submission
// check for matching url
// check for matching name
function add_link_to_file();
}
?>
Please help me figure out how to add a link to the database. I can figure out the rest.
Note: at the bottom of the script I created a function with a few comments. I would like you to also create a validation area so the same url or link name can't be added twice. I don't want to use MySQL. Just a simple fopen with flocking...
Thanks in advance!