我的问题很简单。我正在构建一个普通页面,我需要从moodle数据库访问一些数据,例如当前记录的用户ID,他的消息,发送者...
我想要做的是,通过cookie或其他东西获取当前用户的消息登录moodle。
我在一些地方读到我可以包含config.php,然后获取global $USER
,但我想求助于cookie会话。
我可以访问消息,因为我有数据库的登录信息,但我需要知道当前连接的用户,所以我可以检索他/她的邮件。
有没有办法在不必直接包含moodle安装的页面的情况下获取此信息?
谢谢!
编辑更清楚,我需要访问moodle外部的全局$USER
(或包含当前登录用户的内容)。我可以访问moodle数据库。
答案 0 :(得分:1)
您可以将config.php用于此目的。
<?php
require_once("yourwebsite./config.php") ; //this assumes your php file is in a subdirectory of your moodle
require_login(); //Won't do any good to 'get' a username 'til sombody's logged in.
echo $USER->username;
echo $USER->firstname; // and so on..
?>
来源Moodle论坛:https://moodle.org/mod/forum/discuss.php?d=60634 https://moodle.org/mod/forum/discuss.php?d=55654&parent=253937