JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
clean up my urls
[wfpl.git] / session_messages.php
1 <?php
2
3 #  Copyright (C) 2007 Jason Woofenden
4 #
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #  
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #  
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 # require_once() this file instead of messages.php if you'd like to store
20 # save/restore messages in the session accross redirect()s. That's all you have
21 # to do. These functions are called when needed (from redirect() and
22 # display_messages()) if they are defined.
23
24 # see messages.php for documentation on how to use it.
25
26 require_once(__DIR__.'/'.'session.php');
27 require_once(__DIR__.'/'.'string_array.php');
28 require_once(__DIR__.'/'.'messages.php');
29
30 function session_save_messages() {
31         if(!isset($GLOBALS['wfpl_messages'])) {
32                 return;
33         }
34         if(!is_array($GLOBALS['wfpl_messages'])) {
35                 return;
36         }
37
38         init_session();
39         session_set('wfpl_messages', array_to_string($GLOBALS['wfpl_messages']));
40 }
41
42 function session_restore_messages() {
43         if(session_exists()) {
44                 $messages = session_get('wfpl_messages');
45                 if($messages !== false) {
46                         session_clear('wfpl_messages');
47                         return string_to_array($messages);
48                 }
49         }
50         return array();
51 }