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?
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With