invalidsesskey

invalidsesskey

by Aditya Dubay -
Number of replies: 10

Hi,

I am using Moodle 3.2.2

We are taking exam of 11000 students through Moodle.

We face below error quite frequently:

invalidsesskey

Incorrect sesskey submitted, form not accepted!

File: /lib/setuplib.php
Line: 496
 
Stack trace:
Error code: invalidsesskey* line 496 of /lib/setuplib.php: moodle_exception thrown* line 85 of /lib/sessionlib.php: call to print_error()* line 216 of /lib/externallib.php: call to require_sesskey()* line 59 of /lib/ajax/service.php: call to external_api::call_external_function()

How to get rid of above error.

Please help.

 

Attachment invalidSessKey.png
Average of ratings: -
In reply to Aditya Dubay

Re: invalidsesskey

by Colin Fraser -
Picture of Documentation writers Picture of Testers

This is a serious annoyance but the reasons for this are likely to be: 

The most likely reason for obtaining an "Invalid Sesskey" message is because your session has timed out i.e. you were inactive for an extended period. Please log in again.

Other possible reasons are:

  1. Your site doesn't have the PHP setting "session.auto_start=0" (see Installing Moodle - software)
  2. You logged out at some time between opening the form and submitting it.
  3. You have followed a bad link to a form script.
  4. Your database has an incorrect value for sessioncookiepath in the mdl_config table.
  5. You edited the code in a file on the server while logged in to your moodle website.
Courtesy of Moodle Docs... 


In reply to Colin Fraser

Re: invalidsesskey

by Aditya Dubay -

Hi Colin,

Thanks for reply.

As per your points what I understand is (Please correct me if I went in wrong direction):

01. session.auto_start must be set "1"

02. This point I did not understand.

03. This point I did not understand.

04. I do not found "sessioncookiepath" in mdl_config

05. This point I did not understand.

Can you please explain it little more for me I am not a coder so sometimes I took time to understand these kind of stuff.

In reply to Aditya Dubay

Re: invalidsesskey

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Hi Aditya, usually, AFAIK, it is not logging out properly that causes an issue with this problem. The sesskey is not terminated properly, remains open and active when the student returns. So please make sure students log out properly. 

For the rest, do you have access to the server? Or, do you have someone who has editing rights to the php.ini file, the Moodle database and Moodle codebase? 

In the php.ini file, I would expect, there is a line which should read "session.auto_start=0" which would indicate the that the session is going to start at load. But, IMNAD, so am just guessing here. This may be hard coded somewhere in the million lines of code that make up Moodle.

In the database, the mdl_config table has a field called : sessioncookiepath. This is a value that can be set in the Moodle config page, if I am getting it right, which would be in the folder that all cookies are aimed at, the User's cookie path.

Also, this is from Ken Task, who is quite usually right with this kind of technical jibberish.smile

If you have access to command line, try this:

First, take a look at the files contained in moodledata/sessions

ls /path/to/moodledata/sessions

The only reason for doing that is to see what's there now so that when you execute below one can tell it's working. ;)

Then

cd /admin/tool/task/cli

php schedule_task.php --execute=\\core\\task\\session_cleanup_task

That might take some time if there are sessions that need to be 'cleaned up' so be patient and let it run.

'spirit of sharing', Ken

He also suggests this should be run regularly. 

  


Average of ratings: Useful (2)
In reply to Colin Fraser

Re: invalidsesskey

by Aditya Dubay -

Hi Colin,

Thanks for reply.

I try to troubleshoot and do the changes you suggest smile

In reply to Aditya Dubay

Re: invalidsesskey

by fiona Maina -

I was having a similar problem while running a Moodle off a shared cloud server. 


This is how I did it:

(i) Launch cPanel

(ii) Go To Cache Manager

(iii) Under ByPass Domain, I enabled the ByPass on my site so that the site contents are not cached.

.....This seemed to solve the problem.


Good Luck!




In reply to fiona Maina

Re: invalidsesskey

by Aditya Dubay -

Hi Fiona,

Thanks for reply.

I didnt found Cache Manager in cPanel.

After disabling Nginix I didnt got this error till now.

In reply to Aditya Dubay

Re: invalidsesskey

by Andrew Normore -
Hi everyone, DISABLE YOUR CDN CACHE. In some cases it is CloudFront, in my case it was Securi.net -- it is trying to serve cached content to your user, which doesn't match, so it throws this error.

So simply turned "Cache mode" to disabled on our CDN provider.
In reply to Andrew Normore

Re: Re: invalidsesskey

by Aditya Dubay -
Hi Andrew,

Thanks for your suggestion smile
I will check.
Although disabling Nginix worked for me smile
In reply to Aditya Dubay

Re: Re: Re: invalidsesskey

by Andrew Normore -
So -- why did nginX being disabled help you?

Because nginX has a really robust caching engine -- BY DEFAULT! That's one of the reasons it's recommended for speed oriented websites. smile

PS: Just setup another Moodle install and it had weird, weird results. Forgot to turn the CDN off on that website too. All good now...
In reply to Andrew Normore

Re: invalidsesskey

by Gopakumar Velukkutty -

Hi Andrew Noremore,

 I had the same problem faced by Aditya. I do not have nginx running. I am not using CDN. But I get invalid session key almost every time. 

Will you help me to solve this problem.