这是我所做的
1 -我启用了(外部数据库)身份验证插件
2 -在文件夹中创建这个 php 文件 (my/moodle/root/login/)
<?php
require('../config.php');
$username = $_GET['id'];// 's3265';
$serverName = 'moodle' ;
$connectionInfo = array( "UID"=>"mssqlUser","PWD"=>"********","Database"=>"external_Database");
//I am using MSSQL2008
echo '<form action="' . $CFG->wwwroot .
'/login/index.php" method="post" name="login" id="form">';
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if (!$conn)
{die('Could not connect: ' . sqlsrv_error());}
$result = sqlsrv_query($conn , "SELECT * FROM Users WHERE LoginID = '" . $username . "'");
var_dump($conn, $result);
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
{
echo $row['FName'] . " " . $row['LName'] . ", please wait. . .";
$password = $row['LoginPassword'];
}
sqlsrv_close($conn);
?>
<p><input type="hidden" name="username" value="<?php echo $username ?>">
<p><input type="hidden" name="password" value="<?php echo $password ?>">
<script language="JavaScript">
function Validate(){document.login.submit();}
Validate();
</script>
</form>
3 -假设您命名了 rhr 文件(test.php)
现在您的链接(http://your_domain/moodle/login/test.php?id=yourusername)
在我看来应该可以正常工作,但是 . . . 我不关心安全。. . 如果你这样做。. . 您必须为此添加一些内容