JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / session_messages.php
1 <?php
2
3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
7
8
9 # require_once() this file instead of messages.php if you'd like to store
10 # save/restore messages in the session accross redirect()s. That's all you have
11 # to do. These functions are called when needed (from redirect() and
12 # display_messages()) if they are defined.
13
14 # see messages.php for documentation on how to use it.
15
16 require_once(__DIR__.'/'.'session.php');
17 require_once(__DIR__.'/'.'messages.php');
18
19 function session_save_messages() {
20         if(!isset($GLOBALS['wfpl_messages'])) {
21                 return;
22         }
23         if(!is_array($GLOBALS['wfpl_messages'])) {
24                 return;
25         }
26         if(!count($GLOBALS['wfpl_messages'])) {
27                 return;
28         }
29
30         init_session();
31         session_set('wfpl_messages', json_encode($GLOBALS['wfpl_messages']));
32 }
33
34 function session_restore_messages() {
35         if(session_exists()) {
36                 $messages = session_get('wfpl_messages');
37                 if($messages !== false) {
38                         session_clear('wfpl_messages');
39                         $messages = json_decode($messages, true);
40                         if ($messages !== null) {
41                                 return $messages;
42                         }
43                 }
44         }
45         return array();
46 }