Jag har en inloggningssida och nu tänkte jag kolla vilket som är det smidigaste och säkraste sättet att kolla mot en mysql-databas om användaren lyckas logga in med dom uppgifter den angav.
Just nu kör jag med:
$result = mysql_query("SELECT * FROM Users WHERE U_Name = '$Username'
AND U_Pass = '$Password' LIMIT 1") or die("Could not query:" . mysql_error());
$row = mysql_fetch_assoc($result);
if ($row['U_Name']) {
$_SESSION["U_Id"] = $row['U_Id'];
$_SESSION["U_Name"] = $row['U_Name'];
$_SESSION["U_Pass"] = $row['U_Pass'];
} else {
header("Location: index.php");
}
Men jag kör $Username och $Password genom denna funktion innan(Jag har lånat koden från någonstans men vet inte vart :( ):
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
Någon som vet ett bättre sätt eller finns det något osäkert med detta?