我正在尝试检查用户名是否在我的一个数据库中。
$mysqli->prepare("SELECT username FROM table WHERE username = ?") ...
如果用户名在我的数据库中,我想拥有它们,然后尝试对我的 LDAP 服务器进行身份验证。
if($stmt->num_rows === 0){ ...
下面的代码可以在没有所有 mysqli 的情况下工作,以测试用户名是否在数据库中。现在,如果我尝试登录,我会遇到:
致命错误:在第 22 行调用 C:\xampp\htdocs\webapp\login.php 中未定义的方法 mysqli_stmt::get_result()
<?php
require_once('config.php'); //db connection
//error_reporting(0);
if (isset($_POST['submitted'])) {
$username =$_POST['username'];
$password=$_POST['password'];
$ldap = ldap_connect("localserv1.local.com", 389) or exit ("Error connecting to LDAP server.");
//Settings for AD
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
//Prep statment to check if user is in tblAdmins
if ($stmt = $mysqli->prepare("SELECT username FROM table WHERE username = ?"))
{
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->store_result();
$result = $stmt->get_result();
// Check if the username is in the db
if($stmt->num_rows === 0){
//The user is not in the DB
echo('<p class="error">You are not authorized to view this application.</p><div class="clear"></div>');
}elseif ($bind = ldap_bind($ldap, 'local\\'.$username, $password)) {
//Log them in!
session_register("username");
session_register("password");
header("Location: https://" . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, -9) . "index.php" );
exit;
}else {
// Invalid LDAP user/pass
echo('<p class="error">Invalid username or password.</p><div class="clear"></div>');
}
}else {
//Error
printf("Prep statment failed: %s\n", $mysqli->error);
}
}
?>