Log in with username/password: lyceum/lyceum

root/branches/1.0/src/lyceum/wp-settings.php

Revision 1273, 9.4 kB (checked in by jjb, 2 years ago)

#885, #729

  • Sessions last for 10 years, and sessions are not "garbage collected" for 10 years.
  • The user may specify a custom path for session data to be stored
  • The user may turn on the experimental DB session storage system

There is a jumble of mediocre documentation about the various dimensions in php sessions-- the consensus seems to be that session data might be "garbage collected" before the session data expires. I cannot imagine what "garbage collection" could possibly mean in this case-- in call other cases in computer science it means data that the program is absolutely certain is not being used by some part of the system. Here it seems to be a simplistic notion of time-based expiration.

Theses were helpful:
http://www.captain.at/howto-php-sessions.php
http://www.php.net/manual/en/ref.session.php#68537

Line 
1 <?php
2 // Turn register globals off
3 function unregister_GLOBALS() {
4     if ( !ini_get('register_globals') )
5         return;
6
7     if ( isset($_REQUEST['GLOBALS']) )
8         die('GLOBALS overwrite attempt detected');
9
10     // Variables that shouldn't be unset
11     $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
12     
13     $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
14     foreach ( $input as $k => $v )
15         if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
16             $GLOBALS[$k] = NULL;
17             unset($GLOBALS[$k]);
18         }
19 }
20
21 unregister_GLOBALS();
22
23 unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories );
24
25 if ( ! isset($blog_id) )
26     $blog_id = 1;
27
28 // Fix for IIS, which doesn't set REQUEST_URI
29 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
30     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
31     
32     // Append the query string if it exists and isn't null
33     if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
34         $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
35     }
36 }
37
38 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
39 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
40     $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
41
42 // Fix for Dreamhost and other PHP as CGI hosts
43 if ( strstr( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) )
44     unset($_SERVER['PATH_INFO']);
45
46 // Fix empty PHP_SELF
47 $PHP_SELF = $_SERVER['PHP_SELF'];
48 if ( empty($PHP_SELF) )
49     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
50
51 function timer_start() {
52     global $timestart;
53     $mtime = explode(' ', microtime() );
54     $mtime = $mtime[1] + $mtime[0];
55     $timestart = $mtime;
56     return true;
57 }
58 timer_start();
59
60 // Change to E_ALL for development/debugging
61 //error_reporting(E_ALL ^ E_NOTICE);
62 //error_reporting(E_ALL);
63
64 // For an advanced caching plugin to use, static because you would only want one
65 if ( defined('WP_CACHE') )
66     require (ABSPATH . 'wp-content/advanced-cache.php');
67
68 define('WPINC', PRIVATE_REL_PATH . 'wp-includes');
69 require_once (ABSPATH . WPINC . '/wp-db.php');
70
71 // Table names
72 $wpdb->posts            = $table_prefix . 'posts';
73 $wpdb->users            = $table_prefix . 'users';
74 $wpdb->categories       = $table_prefix . 'categories';
75 $wpdb->post2cat         = $table_prefix . 'post2cat';
76 $wpdb->comments         = $table_prefix . 'comments';
77 $wpdb->links            = $table_prefix . 'links';
78 $wpdb->linkcategories   = $table_prefix . 'linkcategories';
79 $wpdb->options          = $table_prefix . 'options';
80 $wpdb->postmeta         = $table_prefix . 'postmeta';
81 $wpdb->usermeta         = $table_prefix . 'usermeta';
82 $wpdb->blogs            = $table_prefix . 'blogs';
83 $wpdb->postsearch       = $table_prefix . 'postsearch';
84 $wpdb->sessions         = $table_prefix . 'sessions';
85
86 $wpdb->prefix           = $table_prefix;
87
88 if ( defined('CUSTOM_USER_TABLE') )
89     $wpdb->users = CUSTOM_USER_TABLE;
90 if ( defined('CUSTOM_USER_META_TABLE') )
91     $wpdb->usermeta = CUSTOM_USER_META_TABLE;
92
93 $tableposts = $wpdb->posts;
94 $tableusers = $wpdb->users;
95 $tablecategories = $wpdb->categories;
96 $tablepost2cat = $wpdb->post2cat;
97 $tablecomments = $wpdb->comments;
98 $tablelinks = $wpdb->links;
99 $tablelinkcategories = $wpdb->linkcategories;
100 $tableoptions = $wpdb->options;
101 $tablepostmeta = $wpdb->postmeta;
102
103 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
104     require (ABSPATH . 'wp-content/object-cache.php');
105 else
106     require (ABSPATH . WPINC . '/cache.php');
107
108 // To disable persistant caching, add the below line to your wp-config.php file, uncommented of course.
109 define('DISABLE_CACHE', true);
110
111 wp_cache_init();
112
113 require (ABSPATH . WPINC . '/functions.php');
114 require (ABSPATH . WPINC . '/default-filters.php');
115 require_once (ABSPATH . WPINC . '/wp-l10n.php');
116
117 // $wpdb->hide_errors();
118 // $db_check = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
119 // if ( !$db_check && (!strstr($_SERVER['PHP_SELF'], 'install.php') && !defined('WP_INSTALLING')) ) {
120 //     if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') )
121 //         $link = 'install.php';
122 //     else
123 //         $link = 'wp-admin/install.php';
124 //     die(sprintf(__("It doesn't look like you've installed WP yet. Try running <a href='%s'>install.php</a>."), $link));
125 // }
126 // $wpdb->show_errors();
127
128 require (ABSPATH . WPINC . '/functions-formatting.php');
129 require (ABSPATH . WPINC . '/functions-post.php');
130 require (ABSPATH . WPINC . '/capabilities.php');
131 require (ABSPATH . WPINC . '/classes.php');
132 require (ABSPATH . WPINC . '/template-functions-general.php');
133 require (ABSPATH . WPINC . '/template-functions-links.php');
134 require (ABSPATH . WPINC . '/template-functions-author.php');
135 require (ABSPATH . WPINC . '/template-functions-post.php');
136 require (ABSPATH . WPINC . '/template-functions-category.php');
137 require (ABSPATH . WPINC . '/comment-functions.php');
138 require (ABSPATH . WPINC . '/feed-functions.php');
139 require (ABSPATH . WPINC . '/links.php');
140 require (ABSPATH . WPINC . '/kses.php');
141 require (ABSPATH . WPINC . '/version.php');
142 require (LYCEUMSRCROOT . 'lib/functions.php');
143 require (LYCEUMSRCROOT . 'lib/backport.php');
144 require (LYCEUMSRCROOT . 'lib/lyceum-registration-functions.php');
145 require (LYCEUMSRCROOT . 'lib/session.php');
146
147 //TODO use cache
148 if (!isset($blogdata)){
149     if(SUBDOMAINS) {
150         $host = $_SERVER['HTTP_HOST'];
151         if( false !== ( $pos = strpos($host, '.'.MAINDOMAIN)) )
152             $slug = substr($host, 0, $pos);
153         elseif ($_POST['comment_post_ID'])
154             $slug = slug_from_postid((int)$_POST['comment_post_ID']);
155         elseif (DEFAULTBLOG)
156             $slug = DEFAULTBLOG;
157         else
158             //if( !(strpos($_SERVER['REQUEST_URI'], '/system-admin')===0 || strpos($_SERVER['REQUEST_URI'], '/wp-')===0) )
159             header('Location: '.WEBROOT.'/portal.php');
160     } else {
161         if (!isset($_REQUEST['b']))
162             if (DEFAULTBLOG)
163                 $slug = DEFAULTBLOG;
164             else
165                 header('Location: '.WEBROOT.'/portal.php');
166         else
167             $slug = $_REQUEST['b'];
168     }
169     $blogdata = $wpdb->get_row("SELECT slug, id, status FROM `$wpdb->blogs` WHERE `slug`='" . mysql_real_escape_string($slug) ."'");
170     $blog = $blogdata->id;
171     $blogstatus = $blogdata->status;
172 }
173 if (!isset($blog))
174     $blog = 'NULL';
175
176 define('LURL', 'http://' . MAINDOMAIN . WEBROOT);// Lyceum URL
177
178 if (!strstr($_SERVER['PHP_SELF'], 'install.php')) :
179     // Used to guarantee unique hash cookies
180     $cookiehash = md5(LURL); // Remove in 1.4
181     define('COOKIEHASH', $cookiehash);
182 endif;
183
184 if ( !defined('USER_COOKIE') )
185     define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
186 if ( !defined('PASS_COOKIE') )
187     define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
188 if ( !defined('COOKIEPATH') )
189     define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_settings('home') . '/' ) );
190 if ( !defined('SITECOOKIEPATH') )
191     define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', LURL . '/' ) );
192
193 define('COOKIE_DOMAIN', '.'. preg_replace('|:\d+$|','',MAINDOMAIN));
194
195 require (ABSPATH . WPINC . '/vars.php');
196
197 // Check for hacks file if the option is enabled
198 if (get_settings('hack_file')) {
199     if (file_exists(ABSPATH . '/my-hacks.php'))
200         require(ABSPATH . '/my-hacks.php');
201 }
202
203 if ( get_settings('active_plugins') || get_settings('active_system_plugins')) {
204     $active_plugins = get_settings('active_plugins');
205     $active_system_plugins = get_settings('active_system_plugins');
206     if (!is_array($active_plugins)) $active_plugins = array();
207     if (!is_array($active_system_plugins)) $active_system_plugins = array();
208     $current_plugins = array_merge($active_plugins, $active_system_plugins);
209     if ( is_array($current_plugins) ) {
210         foreach ($current_plugins as $plugin) {
211             if ('' != $plugin && file_exists(ABSPATH . 'wp-content/plugins/' . $plugin))
212                 include_once(ABSPATH . 'wp-content/plugins/' . $plugin);
213             else if ('' != $plugin && file_exists(ABSPATH . 'wp-content/systemplugins/' . $plugin))
214                 include_once(ABSPATH . 'wp-content/systemplugins/' . $plugin);
215         }
216     }
217 }
218
219 require (ABSPATH . WPINC . '/pluggable-functions.php');
220
221 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
222     wp_cache_postload();
223
224 do_action('plugins_loaded');
225
226 // If already slashed, strip.
227 if ( get_magic_quotes_gpc() ) {
228     $_GET    = stripslashes_deep($_GET   );
229     $_POST   = stripslashes_deep($_POST  );
230     $_COOKIE = stripslashes_deep($_COOKIE);
231 }
232
233 // Escape with wpdb.
234 $_GET    = add_magic_quotes($_GET   );
235 $_POST   = add_magic_quotes($_POST  );
236 $_COOKIE = add_magic_quotes($_COOKIE);
237 $_SERVER = add_magic_quotes($_SERVER);
238
239 do_action('sanitize_comment_cookies');
240
241 $wp_the_query =& new WP_Query();
242 $wp_query     =& $wp_the_query;
243 $wp_rewrite   =& new WP_Rewrite();
244 $wp           =& new WP();
245
246 define('TEMPLATEPATH', get_template_directory());
247
248 // Load the default text localization domain.
249 load_default_textdomain();
250
251 // Pull in locale data after loading text domain.
252 require_once(ABSPATH . WPINC . '/locale.php');
253
254 // Load functions for active theme.
255 if ( file_exists(TEMPLATEPATH . "/functions.php") )
256     include(TEMPLATEPATH . "/functions.php");
257
258 function shutdown_action_hook() {
259     do_action('shutdown');
260     wp_cache_close();
261 }
262 register_shutdown_function('shutdown_action_hook');
263
264 if (defined('SESSIONPATH'))
265     ini_set('session.save_path', SESSIONPATH);
266
267 $timeout = 315569260// 315569260 seconds = 10 years
268 ini_set('session.gc_maxlifetime', $timeout);
269 session_set_cookie_params( $timeout, '/', '.'.MAINDOMAIN );
270 session_start();
271
272 // Everything is loaded and initialized.
273 do_action('init');
274
275 ?>
276
Note: See TracBrowser for help on using the browser.
Log in with username/password: lyceum/lyceum