0

ユーザー名がデータベースの1つにあるかどうかを確認しようとしています。

$mysqli->prepare("SELECT username FROM table WHERE username = ?") ...

ユーザー名がデータベースにある場合は、それらを使用して、LDAPサーバーへの認証を試みます。

if($stmt->num_rows === 0){ ...

以下のコードは、すべてのmysqliがなくても機能し、ユーザー名がDBにあるかどうかをテストします。今、ログインしようとすると、次のように表示されます。

致命的なエラー: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);
            }
    }
    ?>
4

1 に答える 1

1

PHPのマニュアルページのコメントget_resultは、その関数を機能させるために「mysqlndドライバー」が必要になる可能性があることを示唆しています。

実際には$result変数を使用していないので、簡単な回避策としてその行を完全に削除できます。

于 2012-08-23T03:21:53.953 に答える