Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/lib/ -> sessionlib.php (source)

Differences Between: [Versions 310 and 311] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

(no description)

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
Copyright: 2008, 2009 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 240 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 7 functions


Functions that are not part of a class:

sesskey()   X-Ref
Makes sure that $USER->sesskey exists, if $USER itself exists. It sets a new sesskey
if one does not already exist, but does not overwrite existing sesskeys. Returns the
sesskey string if $USER exists, or boolean false if not.

return: string

confirm_sesskey($sesskey=NULL)   X-Ref
Check the sesskey and return true of false for whether it is valid.
(You might like to imagine this function is called sesskey_is_valid().)

Every script that lets the user perform a significant action (that is,
changes data in the database) should check the sesskey before doing the action.
Depending on your code flow, you may want to use the {@link require_sesskey()}
helper function.

param: string $sesskey The sesskey value to check (optional). Normally leave this blank
return: bool whether the sesskey sent in the request matches the one stored in the session.

require_sesskey()   X-Ref
Check the session key using {@link confirm_sesskey()},
and cause a fatal error if it does not match.


is_moodle_cookie_secure()   X-Ref
Determine wether the secure flag should be set on cookies

return: bool

set_moodle_cookie($username)   X-Ref
Sets a moodle cookie with a weakly encrypted username

param: string $username to encrypt and place in a cookie, '' means delete current cookie
return: void

get_moodle_cookie()   X-Ref
Gets a moodle cookie with a weakly encrypted username

return: string username

cron_setup_user($user = null, $course = null, $leavepagealone = false)   X-Ref
Sets up current user and course environment (lang, etc.) in cron.
Note: This function is intended only for use in:
- the cron runner scripts
- individual tasks which extend the adhoc_task and scheduled_task classes
- unit tests related to tasks
- other parts of the cron/task system

param: stdClass $user full user object, null means default cron user (admin),
param: stdClass $course full course record, null means $SITE
param: bool $leavepagealone If specified, stops it messing with global page object
return: void