Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check whether user are login in moodle?

Currently I'm using moodle to create a site. I want to create a function if user not login they will redirect to the login page. How can I do that in moodle?

like image 893
Beginner Pogrammer Avatar asked Nov 29 '22 19:11

Beginner Pogrammer


2 Answers

Assumption - Writing a custom page in PhP, hosted on same server on moodle site.

Then the page will have access to the session information and the task is very straighforward.

First you call the moodle bootstap, then call the moodle function to check for a valid login.

require_once('../../config.php');  // specify path to moodle /config.php file

// require valid moodle login.  Will redirect to login page if not logged in.
require_login();

// if you also include the id number of a course then require permisision to view a particular course 
require_login(78);  // requires login and permission to view course id 78.
like image 108
digitalsean Avatar answered Dec 09 '22 10:12

digitalsean


Following code snippet might be of some help

require_once('/home/public-html/moodle/config.php'); 
if (!isloggedin()) {
    //redirect to moodle login page
} else {
    //do whatever you want here
}
like image 20
iankit Avatar answered Dec 09 '22 10:12

iankit