View Full Version : Control Panel
shwaza
12-11-2004, 10:30 AM
Hi, I'm thinking of making a page (password protected ofc) that will be able to do a few things. First, i want it to be able to edit all rows of tables i have on my site, that part im pretty sure i would be able to do with a little help from you guys ;) then next im wondering if its possible to have an upload thing, so that selected people i choose, not just random people who feel like uploading things, could upload things into my public_html folder, without logging into cpanel or anything, i was thinking this may be able to be accomplished with ftp but im not sure. Anyone have any ideas?
Definately possible. Can be done without PHP, too.
I would say, make a table, in your DB named "admins", with 3 fields - username(VARCHAR, length 255), password(also VARCHAR 255), and perms(TINYINT, length 1). Then, using what you see at http://www.zend.com/zend/tut/authentication.php make a log in system, kind of like:
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Connect to MySQL
mysql_connect( 'localhost', 'username', 'password' )
or die ( 'Unable to connect to server.' );
// Select database on MySQL server
mysql_select_db( 'your_db' )
or die ( 'Unable to select database.' );
// Formulate the query
$encrypted = md5($PHP_AUTH_PW);
$sql = "SELECT * FROM admins WHERE
username = '$PHP_AUTH_USER' AND
password = '$encrypted'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
// Get perm levels
while($c = mysql_fetch_object($result)) {$perm = $c->perms; }
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
}
// We are authenticated. Continue from here...
Let's say, that if your perm level is set to 0, you can upload, and if it's set to 1, you can edit your mysql db. Let's start with the uploading. Make sure you CHMOD your public_html folder to 666, first, though, or we won't be able to upload. Take a look at this Zend tutorial, too: http://www.zend.com/zend/spotlight/uploading.php
// Switch the act variable (obtained from the address)
$act = $_GET['act'];
if ($act == "home" || $act == "")
{ // No actions are being performed. See what permissions we have..
if ($perm > -1) // We have a 0 or a 1...
{
echo 'Upload Form: <br /><FORM ACTION="?act=upload" METHOD=POST ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="myfile" SIZE=30>
<INPUT TYPE="submit" NAME="Upload File">
</FORM>';
}
if ($perm == 1) // We have DB managing permissions..
{
// you'll have to do this part yourself. make a menu or something..
}
}
else if ($act == "upload")
{
if ($perm > -1)
{
// use the code on the Zend site to process and upload the file
}else
{
echo "You dont have permission to upload!";
}
}
else if ($act == "submitsql")
{
// Etc...
}?>
As you can see, I didnt really make a full ACP. Just the concept. The uploading part shouldn't be hard. SQL really depends on your needs. Look up the mySql functions on www.php.net, they should help you.
Good Luck.
Tim :)
shwaza
12-11-2004, 03:58 PM
alright ill get to reading those in a sec, im currently working on a flash film, and i dont really wanna stay away from it for too long ;)
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.