2010-11-03 34 views
2

目前我正在使用moodle創建網站。 我想創建一個函數,如果用戶沒有登錄,他們將重定向到登錄頁面。 我如何在moodle中做到這一點?如何檢查用戶是否在moodle中登錄?

+0

serverfault?目前imade一個category..when用戶不登錄它會說沒有路線..我希望它重定向到登錄頁面.. – 2010-11-03 03:02:49

回答

10

假設 -在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. 
7

下面的代碼片段可能是一些幫助

require_once('/home/public-html/moodle/config.php'); 
if (!isloggedin()) { 
    //redirect to moodle login page 
} else { 
    //do whatever you want here 
} 
1

使用require_login();功能,你可以決定是否要檢查用戶登錄。

2

是的,通過設置很容易地訪問>網站管理員>安全>網站政策

檢查 '強制用戶登錄'

完成:)