gpt4 book ai didi

PHP -> 函数调用中断页面

转载 作者:行者123 更新时间:2023-11-29 21:45:59 25 4
gpt4 key购买 nike

我一直在尝试使用 PHP 和 MySQL 设置登录页面,当我将准备好的语句与 -> 运算符一起使用时,我遇到了问题。我正确安装了 php5 和 apache2,并且 phpinfo(); 运行没有问题,但是当我使用此代码时:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<form action="" method="POST">
<label for="username">Username:</label>
<br />
<input type="text" name="username" id="username" />
<br />
<label for="password">Password:</label>
<br />
<input type="password" name="password" id="password" />
<br />
<input type="submit" value="Submit" />
</form>
<?php
error_reporting(-1);
ini_set('display_errors', 'On');

if (isset($_POST['username']) && isset($_POST['password'])) {
$logged_in = false;

$username = $_POST['username'];
$password = $_POST['password'];

$conn = new mysqli('localhost', 'root', 'password', 'db');

/* create a prepared statement */
if ($stmt = $conn->prepare("SELECT username, password, salt FROM `users` WHERE `username` = ?")) {

/* bind parameters for markers */
$stmt->bind_param("s", $username);

/* execute query */
$stmt->execute();

$stmt->bind_result($storedUser, $storedPassword, $storedSalt);

while ($stmt->fetch()) {
// $storedUser, $storedPassword, $storedSalt
if (crypt($password, $storedSalt) == $storedPassword) {
$logged_in = true;
}
}

/* close statement */
$stmt->close();

if ($logged_in === true) {
echo 'Successfully logged in as ' . $username;
}
}
}

?>
</body>
</html>

php 在 > 处中断,其余部分显示到页面上。

prepare("SELECT username, password, salt FROM `users` WHERE `username` = ?")) { /* bind parameters for markers */ $stmt->bind_param("s", $username); /* execute query */ $stmt->execute(); $stmt->bind_result($storedUser, $storedPassword, $storedSalt); while ($stmt->fetch()) { // $storedUser, $storedPassword, $storedSalt if (crypt($password, $storedSalt) == $storedPassword) { $logged_in = true; } } /* close statement */ $stmt->close(); if ($logged_in === true) { echo 'Successfully logged in as ' . $username; } } } ?> 

最佳答案

虽然我仍然不确定是什么导致了这个问题,但我通过运行修复了它:

sudo /etc/init.d/apache2 stop
sudo apt-get remove --purge apache2 php5
sudo apt-get remove --purge libapache2-mod-php5
sudo apt-get install php5 apache2 libapache2-mod-php5
sudo /etc/init.d/apache2 start
sudo a2enmod php5
sudo /etc/init.d/apache2 force-reload

感谢大家的帮助。

关于PHP -> 函数调用中断页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34113028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com