/// USER AUTHENTICATION AND LOGIN ////////////////////////////////////////
-function require_login($courseid=0) {
+function require_login($courseid=0, $autologinguest=true) {
/// This function checks that the current user is logged in, and optionally
/// whether they are "logged in" or allowed to be in a particular course.
/// If not, then it redirects them to the site login or course enrolment.
+/// $autologinguest determines whether visitors should automatically be
+/// logged in as guests provide $CFG->autologinguests is set to 1
global $CFG, $SESSION, $USER, $FULLME, $MoodleSession;
$SESSION->fromurl = $_SERVER["HTTP_REFERER"];
}
$USER = NULL;
- if (!empty($CFG->autologinguests)) {
- $loginguest = ($courseid and get_field('course','guest','id',$courseid)) ? '?loginguest=true' : '';
+ if ($autologinguest and $CFG->autologinguests and $courseid and get_field('course','guest','id',$courseid)) {
+ $loginguest = '?loginguest=true';
+ } else {
+ $loginguest = '';
}
if (empty($CFG->loginhttps)) {
redirect("$CFG->wwwroot/login/index.php$loginguest");
error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);
}
- require_login(); // Script is useless unless they're logged in
+ require_login(0, false); // Script is useless unless they're logged in
if ($post = data_submitted()) {