简体   繁体   中英

Get moodle current user id externally

my problem is simple. I'm building a plain page where I need to access some data from a moodle database, such as the current logged user ID, his messages, who sent it...

  • The page is hosted locally.
  • Moodle is hosted elsewhere, but I have all the required information to the database (user and password).

What I want to do, is to get the messages of the current user logged in moodle, via the cookies, or something.

I read in a few places that I can just include config.php, then get the global $USER , but i'd like to resort to a cookie session.

I can access the messages since I have the login informations to the database, but I need to know the current connected user, so I can retrieve his/her mails.

Is there a way to get this information without having to directly include pages from the moodle installation?

Thank you!

edit: to be clearer, I need to access the global $USER (or something containing the current logged user) outside moodle. I have access to the moodle database.

You may use the config.php for that purpose.

<?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..

?>

Sources Moodle Forum: https://moodle.org/mod/forum/discuss.php?d=60634 https://moodle.org/mod/forum/discuss.php?d=55654&parent=253937

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM