Moodle Cookie Settings Explained
In this article
Moodle cookie settings control how user authentication, session data, and preferences are stored and managed during interactions with a Moodle learning platform. These settings are configured on the server side by administrators and determine the behavior, security, and lifespan of cookies used across the site.
Background on Moodle and Web Cookies
Moodle, an open-source learning management system (LMS), relies on HTTP cookies to maintain user sessions, remember login states, and personalize the learning experience. Cookies are small pieces of data stored in a user’s browser that allow Moodle to recognize returning users and preserve their activity across pages and visits. Without cookies, users would need to log in repeatedly and lose progress during a session.
By default, Moodle uses several types of cookies: session cookies (temporary), persistent cookies (with expiration), and secure cookies (encrypted in transit). These are essential for core functionality such as course access, quiz attempts, forum posting, and grade tracking. The exact behavior of these cookies is determined by configuration settings in Moodle’s admin panel.
How Moodle Cookie Settings Work
Moodle's cookie handling is primarily governed by configuration variables in the config.php file and the Site Administration interface. Key settings include:
- sessioncookie: Defines the name prefix for session cookies (default:
MoodleSession). - sessioncookiedomain: Specifies the domain for which cookies are valid (e.g.,
.yourschool.edufor subdomain access). - sessioncookiepath: Sets the web path where cookies are active (usually
/for entire site). - sessiontimeout: Determines how long (in seconds) a session remains active after inactivity (default: 7200 seconds or 2 hours).
- cookiesecure: Forces cookies to be sent only over HTTPS if enabled (recommended for secure sites).
- cookietoonly: Restricts cookies to HTTP-only transmission, preventing access via JavaScript (enhances security).
These settings are not typically adjusted by end users but are crucial for administrators managing multi-site setups, subdomains, or single sign-on (SSO) integrations.
Configuring Moodle Cookie Settings
Administrators configure cookie settings through the following steps:
- Log in to Moodle as an administrator.
- Navigate to Site Administration > Server > HTTP.
- Locate the Cookies section.
- Adjust the following fields as needed:
- Cookie domain: Set to a parent domain (e.g.,
.example.com) to allow cookie sharing across subdomains likelearn.example.comandquiz.example.com. - Cookie path: Usually left as
/unless Moodle is installed in a subdirectory (e.g.,/moodle). - Secure cookies: Enable if the site uses HTTPS exclusively.
- HTTP only cookies: Enable to reduce cross-site scripting (XSS) risks.
- Session timeout: Adjust based on security and usability needs—shorter for high-security environments, longer for user convenience.
After changes, save the settings and clear the Moodle cache via Site Administration > Development > Purge caches.
Common Cookie-Related Issues in Moodle
Improper cookie settings can lead to login failures, session drops, or access problems. Common issues include:
- Users logged out unexpectedly: Often caused by mismatched cookie domains or paths, or session timeout set too low.
- Inability to log in: May occur if
cookiesecureis enabled on a non-HTTPS site, preventing cookie transmission. - Problems across subdomains: If the cookie domain isn't prefixed with a dot (e.g.,
.school.org), sessions won't carry over between subdomains. - Browser blocking cookies: Users with strict privacy settings (e.g., Safari Intelligent Tracking Prevention) may experience login issues. Advising users to allow cookies for the Moodle domain can help.
- Shared hosting conflicts: On servers hosting multiple Moodle sites, session cookie name collisions can occur. Customize
sessioncookieto avoid overlap.
Testing changes across different browsers and devices is recommended to ensure compatibility.
Security and Privacy Considerations
Cookie security is critical in educational environments handling personal data. Moodle follows best practices, but administrators must ensure proper configuration:
- Always enable Secure cookies on HTTPS sites to prevent interception.
- Use HTTPOnly to block client-side scripts from accessing session cookies, mitigating XSS attacks.
- Avoid overly long session timeouts to reduce unauthorized access risk if a device is left unattended.
- Comply with privacy regulations (e.g., GDPR, FERPA) by informing users about cookie use in the site’s privacy policy.
- Consider using SameSite attributes (configured at web server level) to prevent cross-site request forgery (CSRF). Moodle 4.0+ respects
SameSite=Laxby default when supported.
Note: Moodle does not use third-party tracking cookies by default, preserving user privacy.
Frequently Asked Questions
How do I fix Moodle login loops caused by cookies?
A login loop often occurs when cookies are blocked or misconfigured. Ensure your browser allows cookies from the Moodle domain. Administrators should verify that cookiesecure is off if not using HTTPS, and that sessioncookiedomain matches the actual domain.
Can Moodle work without cookies?
No, Moodle requires cookies for session management. Disabling cookies in the browser will prevent login and navigation. Session continuity, quiz saving, and forum posting all depend on functional cookies.
Why are my users logged out after 2 hours?
This is the default session timeout (7200 seconds). If longer sessions are needed, increase the sessiontimeout value in Site Administration > Server > HTTP. Note that very long timeouts increase security risks.
How do I share Moodle cookies across subdomains?
Set the sessioncookiedomain to a prefixed domain (e.g., .youruniversity.edu) in the HTTP settings. This allows authentication to persist across courses.youruniversity.edu and exams.youruniversity.edu.
Are Moodle cookies secure?
When properly configured—using HTTPS, secure and HTTPOnly flags, and appropriate timeouts—Moodle cookies are secure. Always keep Moodle updated to benefit from the latest security patches.
Does Moodle support SameSite cookie attributes?
Yes, Moodle 4.0 and later respects SameSite attributes when set at the PHP or web server level (e.g., in php.ini or Apache/Nginx config). This helps prevent CSRF attacks in modern browsers.