我制作了一个 php 登录脚本,但它不起作用。
我的代码:
<?php
function clean($str) { /* sanatize strings for databases & security */
$str = trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
if (!empty($_POST['login_admin'])) {
$username = clean($_POST['name']);
$password = clean($_POST['password']);
try {
$dbh = new PDO('mysql:host=localhost;dbname=imedia', "imedia", "imedia");
$statement = $dbh->prepare("SELECT * FROM administratori WHERE username =:username AND parola =:password");
$statement->execute(array(":username" => $username, ":password" => md5($password)));
$row = $statement->fetch();
if ($row) {
session_start("imedia_admin");
$_SESSION['imedia_admin']['logname'] = $row['username'];
$_SESSION['imedia_admin']['password'] = $row['password'];
echo json_encode("success");
} else {
echo json_encode("error");
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
?>
问题clean
出在功能上,如果不使用它,我的代码可以工作,有人可以解释一下我做错了什么吗?