PDA

View Full Version : Any1 know how to do this ?



GregT
June 8th, 2002, 23:10
Does ne1 know how to make a php or perl script that is like host.sk's createdb.php ? i tryed to make my own but failed miserably, and the person that gives me this script will have there name and website on the bottom of the script , i will prolly have lots of traffic to this page :)

hohoho
June 9th, 2002, 03:16
that's easy to do...i could do one, but i need to know where the script gets all user names and passwords from...from a database to check if they are really hosting members ? :D

hohoho
June 9th, 2002, 03:54
ok...my script is nearly finished...it creates a db called PLDusername, and it creates a mysql user(same username/pass) with rights only in this database ;)

GregT
June 9th, 2002, 13:47
thnx u so much mitja ! all the usernames and passwords are stndard UNIX usernames and passwords so there is no database,

hohoho
June 10th, 2002, 01:13
hmm, i never worked with UNIX/Linux :(
but it should look like this if it was in a database...you can edit it beause i don't know how it works with unix users...

<?
if(isset($submit))
checkuser($username, $password);
else {
echo "<form action=$PHP_SELF method=post>
Username: <input name=username><br>
Password: <input type=password name=password><br>
<input type=submit name=submit value=Submit><input value=Reset type=reset></form>";
}

function checkuser($username, $password) {
$sqlserver = "localhost"; // You NEED to change these 3 variables
$sqluser = "user"; // an mysql user who has all rights
$sqlpass = "pass"; // his password

$link = mysql_connect ($sqlserver, $sqluser, $sqlpass)
or exit ("Couldn't connect to Database Server");

$res = mysql_db_query("users", "SELECT * FROM members");
$num = mysql_num_rows($res);
for($i=0;$i<$num;$i++)
{
$user = mysql_result($res, $i, "user");
$pass = mysql_result($res, $i, "pass");
$password2 = md5($password);
if(strcmp($username, $user)==0 && strcmp($password2,$pass)==0)
createdb($user, $password);
exit;
}
}

function createdb($user, $pass) {
$datab = "PLD$user";
if (mysql_query("CREATE DATABASE $datab")) {
print ("Database was created sucessfully\n");
} else {
printf ("Error: %s\n", mysql_error ());
}
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON $datab.* TO $user@localhost IDENTIFIED BY '$pass'";
mysql_query($sql);
}
?>
I tested it on my computer and it worked ;)

GregT
June 10th, 2002, 01:41
i dont need user checking as the script will be secured with .htaccess , what would the code be that just creates a db and user with the filled out info (the entire chking process cut out)

hohoho
June 10th, 2002, 01:43
it's this funtion:

function createdb($user, $pass) {
$datab = "PLD$user";
if (mysql_query("CREATE DATABASE $datab")) {
print ("Database was created sucessfully\n");
} else {
printf ("Error: %s\n", mysql_error ());
}
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON $datab.* TO $user@localhost IDENTIFIED BY '$pass'";
mysql_query($sql);
}

GregT
June 10th, 2002, 01:49
ok but , how do i take the info from the form



echo "<form action=$PHP_SELF method=post>
Username: <input name=username><br>
Password: <input type=password name=password><br>
<input type=submit name=submit value=Submit><input value=Reset type=reset></form>";
}


and change it to $user and $pass

would it be




$user = username

$pass =password

?

plz help

hohoho
June 10th, 2002, 01:52
hmmm..i don't really know what you mean, but i think it should look like this

<?
if(isset($submit))
createdb($username, $password);
else {
echo "<form action=$PHP_SELF method=post>
Username: <input name=username><br>
Password: <input type=password name=password><br>
<input type=submit name=submit value=Submit><input value=Reset type=reset></form>";
}

function createdb($username, $password) {
$datab = "PLD$user";
if (mysql_query("CREATE DATABASE $datab")) {
print ("Database was created sucessfully\n");
} else {
printf ("Error: %s\n", mysql_error ());
}
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON $datab.* TO $username@localhost IDENTIFIED BY '$password'";
mysql_query($sql);
}
?>

GregT
June 10th, 2002, 01:54
with that code i get Error: Access denied for user: '@localhost' to database 'PLD'

hohoho
June 10th, 2002, 01:56
oh, i forgot the mysql connection code...

<?
if(isset($submit))
createdb($username, $password);
else {
echo "<form action=$PHP_SELF method=post>
Username: <input name=username><br>
Password: <input type=password name=password><br>
<input type=submit name=submit value=Submit><input value=Reset type=reset></form>";
}

function createdb($username, $password) {
$sqlserver = "localhost"; // You NEED to change these 3 variables
$sqluser = "user"; // an mysql user who has all rights
$sqlpass = "pass"; // his password

$link = mysql_connect ($sqlserver, $sqluser, $sqlpass)
or exit ("Couldn't connect to Database Server");

$datab = "PLD$username";
if (mysql_query("CREATE DATABASE $datab")) {
print ("Database was created sucessfully\n");
} else {
printf ("Error: %s\n", mysql_error ());
}
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON $datab.* TO $username@localhost IDENTIFIED BY '$password'";
mysql_query($sql);
}
?>

GregT
June 10th, 2002, 02:02
thnx works great now, thnx mitja ! (i made two little changes to thnx u) :)



<?
if(isset($submit))
createdb($username, $password);
else {
echo "<form action=$PHP_SELF method=post>
Username: <input name=username><br>
Password: <input type=password name=password><br>
<input type=submit name=submit value=Submit><input value=Reset type=reset></form><br>
dbmake.php made by mitja";
}

function createdb($username, $password) {
$sqlserver = "localhost"; // You NEED to change these 3 variables
$sqluser = "user"; // an mysql user who has all rights
$sqlpass = "pass"; // his password

$link = mysql_connect ($sqlserver, $sqluser, $sqlpass)
or exit ("Couldn't connect to Database Server");

$datab = "PLD$username";
if (mysql_query("CREATE DATABASE $datab")) {
print ("Database was created sucessfully\n <br><br> dbmake.php made by mitja");
} else {
printf ("Error: %s\n", mysql_error ());
}
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON $datab.* TO $username@localhost IDENTIFIED BY '$password'";
mysql_query($sql);
}
?>

hohoho
June 10th, 2002, 02:04
you can test the script now...i signed up for PLH and need a mysql database lol

GregT
June 10th, 2002, 02:06
go to http://www.project-linux.org/dbmake.php to signup for dbs ! (Warning do not abuse this script i still need to put a .htaccess file on this to protect it

hohoho
June 10th, 2002, 02:06
wow...it really works :D
if someone tries to abuse, then it will tell him the database already exists :D

GregT
June 10th, 2002, 02:18
Originally posted by mitja
wow...it really works :D
if someone tries to abuse, then it will tell him the database already exists :D

cool :chinese2: