Lo voglio realizzare io, possibilmente nel modo più sicuro possibile. Una bozza che ho preparato è questa:
Codice PHP:
<?php
// Include configuration file
include("conf.php");
session_start();
if ( (!isset($_SESSION["username"])) && (!isset($_SESSION["password"])) && (!isset($_SESSION["admin"])) ) {
echo('<div id="login_form">
<form name="login_form" action="" method="post">
<input type="text" name="username" value="username" style="position: absolute; top: 63px; left: 95px;" />
<input type="text" name="password" value="password" style="position: absolute; top: 102px; left: 95px;" />
<input type="button" value="reset" onclick="fldreset();" style="position: absolute; top: 138px; left: 112px;" />
<input type="submit" value="login" style="position: absolute; top: 138px; left: 193px;" />
</form>
</div>');
// Define the query for finding a user in the database
$search_user = "SELECT username, password, admin FROM " . db_tblprefx . "user WHERE username = '" . $_POST["username"] . "' AND password = '" . md5($_POST["password"]) . "';";
// Search the database for the user who's trying to login
$connect = mysql_connect(db_host, db_username, db_password)
or die("Can't connect to the database... Wrong username or password");
mysql_select_db(db_name, $connect)
or die("Can't connect to the database... The database doesn't exist");
$res = mysql_query($search_user, $connect)
or die("Query failed (user)");
// If user exists and the passwords match
if (mysql_num_rows($res) == 1) {
// Create a record with the result
while ($r = mysql_fetch_assoc($res)) {
$_SESSION["username"] = $r["username"];
$_SESSION["password"] = $r["password"];
$_SESSION["admin"] = $r["admin"];
}
header("Location: cpanel.php");
} else echo("Wrong username or password");
}
?>
Manca l'action nel form che era un $_SERVER['PHP_SELF']. L'ho eliminata per fare delle prove