对PHP还是个新事物,因此仍处于学习阶段。我被要求在多年以前建立的网站上提供帮助,因此数据库仍在使用MD5,我需要对其进行排序 我已经编写了一些代码,但是在最后一部分中,大多数代码仍然可以正常工作。总之,这就是我想要做的
用户登录(因此sql从数据库获取信息) 从此结果中检查密码,如果以XYZ开头,请转到此页面,否则请转到其他页面。 代码在下面,在本地服务器上执行,直到我开始工作
<!DOCTYPE html>
<html>
<body>
<?php
function begnWith($str, $begnString) {
$len = strlen($begnString);
return (substr($str, 0, $len) ===
$beg string);
}
// if(begnWith($text,"$2y"))
//header("Location:
http://www.bbc.co.uk");
// else
//echo "Old MD5";
?>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "login";
// Create connection
$conn = new mysqli($servername,
$username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn-
>connect_error);
}
$sql = "SELECT * FROM users
WHERE username='davsas';";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result-
>fetch_assoc()) {
// echo "<br> id: ". $row["id"]. " -
Name: ". $row["username"]. " " .
$row["password"] . "<br>";
$datas[] = $row;
}
}
foreach ($datas[0] as $data) {
echo $data['password'];
}
if(begnWith($data['password'],"$2y"))
header("Location:
http://www.bbc.co.uk");
else
echo "Old MD5";
//foreach ($datas[0] as $data) {
//echo $data;
//}
//foreach ($datas as $data) {
// echo $data['password'];
//}
$conn->close();
?>
</body>
</html>