目前我正在使用moodle创建一个网站.我想创建一个函数,如果用户没有登录,他们将重定向到登录页面.我怎么能在moodle中做到这一点?
小智 11
假设 -在PhP中编写自定义页面,托管在moodle站点上的同一服务器上.
然后页面将有权访问会话信息,任务非常简单.
首先调用moodle bootstap,然后调用moodle函数检查有效登录.
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.
Run Code Online (Sandbox Code Playgroud)
以下代码段可能会有所帮助
require_once('/home/public-html/moodle/config.php');
if (!isloggedin()) {
//redirect to moodle login page
} else {
//do whatever you want here
}
Run Code Online (Sandbox Code Playgroud)