Moodle Redirect on user logout

Moodle Redirect on user logout

by Baber Ahmed -
Number of replies: 1

Hi All,

Quite new to Moodle but I work with PHP. I have been looking into redirecting to a different website on logout of moodle. I have seen code level hacks... but then I found a thread with a nice plugin that would let me redirect.

Please see below for plugin code:

<?php

require_once('../../lib/authlib.php');

class auth_plugin_logout_redirect extends auth_plugin_base {

function user_login($username, $password) {
return true;
}

function logoutpage_hook() {
global $redirect;
$redirect='http://www.google.com';       //just for testing smile
}
}

?>

In the thread there was also instruction on how to create a folder in "moodle/auth/plugin_name/". In the folder I created "auth.php" and added the source code from above. I then went to admin -> users -> manage authentication. I am told I would find my plugin here but nothing is showing! sad 

I then purposefully changed the name of auth.php to auth_a.php and I got an error message saying that moodle failed to load my plugin. When I changed the name back the error disapeared, but nothing is showing for my plugin not even a plugin loaded confirmation.

1) I need to know if the code above will work as a plugin?
2) Am doing the right things to let moodle know that I want this plugin to run?
3) Is this the correct way to do this particular task or there a better solution?

I am working with Moodle 1.9x

Many Thanks In Advance For Your Help
Bob

Average of ratings: -
In reply to Baber Ahmed

Re: Moodle Redirect on user logout

by Olumuyiwa Taiwo -
Picture of Plugin developers

1) I need to know if the code above will work as a plugin?

You already know that it doesn't smile

2) Am doing the right things to let moodle know that I want this plugin to run?

No. Your plugin needs a constructor, something like:

function auth_plugin_logout_redirect () {

}

Look in the manual auth plugin for the contents of that function.

3) Is this the correct way to do this particular task or there a better solution?

Considering that you don't want to change core code, this would be a correct way of achieving your goal.

Hope that helps.

Muyi