devel:session_handling
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:session_handling [2017-08-02 16:56] – og | devel:session_handling [2023-09-02 09:55] (current) – Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Session handling ====== | ====== Session handling ====== | ||
- | |||
- | FIXME | ||
DokuWiki opens the session in '' | DokuWiki opens the session in '' | ||
- | Depending on when your plugin runs, the session might already have been closed. You can still read a closed session' | + | Depending on when your plugin runs, the session might already have been closed. You can still read a closed session' |
+ | |||
+ | You can also act before the session is closed, for example when catching the DOKUWIKI_STARTED event in an Action plugin: | ||
+ | |||
+ | <code php> | ||
+ | use dokuwiki\Extension\ActionPlugin; | ||
+ | use dokuwiki\Extension\EventHandler; | ||
+ | use dokuwiki\Extension\Event; | ||
+ | |||
+ | class action_plugin_demo extends ActionPlugin { | ||
+ | public function register(EventHandler $contr) { | ||
+ | $contr-> | ||
+ | } | ||
+ | public function session_update(Event $event, $param) { | ||
+ | global $INPUT; | ||
+ | if ($INPUT-> | ||
+ | if (!empty($_POST[' | ||
+ | $_SESSION[" | ||
+ | // optionally saves the persistent data in a cookie | ||
+ | set_doku_pref(" | ||
+ | } else { | ||
+ | unset($_SESSION[" | ||
+ | // optionally removes an associated cookie | ||
+ | set_doku_pref(" | ||
+ | } | ||
+ | return; | ||
+ | } | ||
+ | // This is for all the pages of the site, other than handling the above update | ||
+ | // Optionally loads the cookie | ||
+ | if (!isset($_SESSION[" | ||
+ | $_SESSION[" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This can be used for example in the syntax plugin: | ||
+ | |||
+ | <code php> | ||
+ | class syntax_plugin_demo extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | // Connect and handle the keywords/ | ||
+ | |||
+ | // ... | ||
+ | |||
+ | // main rendering code | ||
+ | function render($mode, | ||
+ | |||
+ | // ... | ||
+ | |||
+ | // At some point, you can create a form to upload persistent data | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | |||
+ | // ... | ||
- | :?: When in code does it close? How to detect? If one tries to (re)open a session | + | // In every page, you can read the persistent data simply by accessing the $_SESSION variable |
+ | msg(" | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
- | :!: To re-open a session, no chars must be sent to the clients browser. | + | Obviously you should tighten |
devel/session_handling.1501685789.txt.gz · Last modified: 2017-08-02 16:56 by og