General developer forum

 
 
Picture of jorge sanchez
logout
 

And tried everything what I can only make a logout button but I find the parameters for a fact that someone can help me Sheetl
thanks

Lo e intentado todo solo me queda realizar un boton de cierre de sesion pero no encuentro los parametros para esto alguien lo a hecho hojala me puedan ayudar
gracias

 
Average of ratings: -
Picture of Andrew Osiname
Re: logout
 

For a logout button (assuming there is not a function you can call in the api), you will probably need to know a bit of PHP/small HTML.

For example, this is the code I see when i inspect what Moodle uses to logout of the system

a href="http://domain.ac.uk/login/logout.php?sesskey=sX4acy1PXa"

You need to access the file called logout.php and pass a sessionkey variable. This variable is different every time you log in and different for each user.

The easiest way to do it is to use a hyperlink as above (and just use css to make it look like a button) that links to /login/logout.php

Before coding the link, you need to get the session variable for the current user so you can pass it to the logout.php file as above: ?sesskey=blah blah

This allows the system to know who to logout.

To get the sesskey you will need something like$_GET['session_key'] but that may not be safe so I would read the logout.php file and see how they got the key there and copy that method.

Hope that helps

 
Average of ratings: -
Picture of Andrew Osiname
Re: logout
 

Here is how to do it

[php]
global $USER;
$sesskey = $USER->sesskey;
$logout = '<a href="http://yourdomain.com/login/logout.php?sesskey='.$sesskey.'">Logout</a>';
[/php]

This prints a logout link like at the top right of this page. you can give the anchor an id or class and style it into a button

 
Average of ratings: -
Picture of Rafael Vicenzo
Re: logout
 

Thanks!

 
Average of ratings: -
Picture of Hubert Chathi
Re: logout
 
This allows the system to know who to logout.

No, who to log out is always the current user. This is to make sure that only Moodle-created links can log a user out. This is to prevent a malicious user from fooling a Moodle user into clicking a link that causes them to be logged out of Moodle, since the malicious user doesn't know the user's session key. (Logging out might not be too terrible, but other pages are similarly protected.)

You can get the current user's session key by calling the sesskey() function.

 
Average of ratings:Useful (1)
Picture of Andrew Osiname
Re: logout
 

Thanks for the correction. Can you by any chance help with: http://moodle.org/mod/forum/discuss.php?d=166073#p728009 ?

Thanks

 
Average of ratings: -