$SESSION info

$SESSION info

by Fred Riley -
Number of replies: 3

A simple question: where can I find out documentation on what's in the global variable/object $SESSION? More specifically, I'm trying to find the current session ID. I have tried:

        var_dump($SESSION);

and got output such as that below, which takes some parsing and doesn't appear to mention the session id.

I've searched TFM, TFFAQs, TFFora, and even a famous Internet search engine, with various search strings, very likely the wrong ones. I can find info on various other global variables in the Core APIs section, but can't find a thing on $SESSION. I suspect that $SESSION is an object which aliases the PHP global variable $_SESSION, which is fine, but I could really do with knowing what its keys are. For instance, the /course/changenumsections.php script requires a valid session ID.

Still burrowing through the dense undergrowth...

Fred


Output from var_dump($SESSION):


object(stdClass)#80 (6) { ["cachestore_session"]=> array(2) { ["default_session-core/coursecat"]=> array(4) { ["__lastaccess__u2_"]=> array(2) { [0]=> int(1406116964) [1]=> int(1406116964) } ["u2__85c88a1a4f00de47df4ef5d63178e7e05bbadafc"]=> array(2) { [0]=> int(1406116964) [1]=> int(1406116964) } ["u2__5f2ef559d3765b3ac21ad43b1851a8baf7d2cad9"]=> array(2) { [0]=> array(5) { [0]=> int(4) [1]=> int(6) [2]=> int(5) [3]=> int(2) [4]=> int(3) } [1]=> int(1406116964) } ["u2__605d8560c5b236c41a782f6aaae75c63b8a4159d"]=> array(2) { [0]=> int(5) [1]=> int(1406116964) } } ["default_session-core/userselections"]=> array(1) { ["__lastaccess__u2_"]=> array(2) { [0]=> int(1406116256) [1]=> int(0) } } } ["navcache"]=> object(stdClass)#79 (1) { ["navigation"]=> array(4) { ["userblogoptions2"]=> array(3) { [0]=> int(1406116256) [1]=> string(1) "2" [2]=> string(697) "a:2:{s:4:"view";a:2:{s:6:"string";s:22:"View all of my entries";s:4:"link";O:10:"moodle_url":9:{s:9:"*scheme";s:4:"http";s:7:"*host";s:9:"localhost";s:7:"*port";s:0:"";s:7:"*user";s:0:"";s:7:"*pass";s:0:"";s:7:"*path";s:22:"/moodle/blog/index.php";s:16:"*slashargument";s:0:"";s:9:"*anchor";N;s:9:"*params";a:1:{s:6:"userid";s:1:"2";}}}s:3:"add";a:2:{s:6:"string";s:15:"Add a new entry";s:4:"link";O:10:"moodle_url":9:{s:9:"*scheme";s:4:"http";s:7:"*host";s:9:"localhost";s:7:"*port";s:0:"";s:7:"*user";s:0:"";s:7:"*pass";s:0:"";s:7:"*path";s:21:"/moodle/blog/edit.php";s:16:"*slashargument";s:0:"";s:9:"*anchor";N;s:9:"*params";a:1:{s:6:"action";s:3:"add";}}}}" } ["contexthasrepos5"]=> array(3) { [0]=> int(1406116256) [1]=> string(1) "2" [2]=> string(4) "b:0;" } ["contexthasrepos15"]=> array(3) { [0]=> int(1406116969) [1]=> string(1) "2" [2]=> string(4) "b:0;" } ["contexthasrepos163"]=> array(3) { [0]=> int(1406118053) [1]=> string(1) "2" [2]=> string(4) "b:0;" } } } ["load_navigation_admin"]=> int(1) ["admin_critical_warning"]=> int(0) ["calendarshoweventtype"]=> int(15) ["fromdiscussion"]=> string(44) "http://localhost/moodle/course/view.php?id=2" }


Average of ratings: -
In reply to Fred Riley

Re: $SESSION info

by Davo Smith -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

I don't think I've ever come across anything in Moodle needing a session ID. A quick look at the changenumsections.php code shows a 'require_sesskey()' function, but no obvious mention of a 'session ID'.

If it is in fact the sesskey you are looking for, then just call sesskey() to retrieve it for the current user session (which, if you look inside require_sesskey(), that is exactly the function used to retrieve the value to check against).


In reply to Davo Smith

Re: $SESSION info

by Fred Riley -

Thanks, Davo. A colleague told me the same just after I'd posted my query, to use sesskey(), which I will do. This is another undocumented function, it seems, which is my excuse for not having come across it. Whilst I don't mind digging into functions and going up call hierarchies (as I think of them), it is a bit more time-consuming than having a nice doc to read.

Fred