lainchan/inc/user.php

26 lines
1.1 KiB
PHP
Raw Normal View History

2010-11-02 06:57:33 -04:00
<?php
2010-12-10 05:03:20 -05:00
// 'false' means that the user is not logged in as a moderator
$mod = false;
2010-11-02 06:57:33 -04:00
2010-12-01 00:42:48 -05:00
// Set the session name.
2011-02-12 01:25:15 -05:00
session_name($config['cookies']['session']);
2010-11-02 06:57:33 -04:00
2010-12-01 00:42:48 -05:00
// Set session parameters
2011-02-12 01:25:15 -05:00
session_set_cookie_params(0, $config['cookies']['jail']?$config['root']:'/');
2010-12-01 00:42:48 -05:00
// Start the session
2010-12-01 00:43:36 -05:00
session_start();
2010-12-01 00:42:48 -05:00
// Session creation time
2010-11-02 06:57:33 -04:00
if(!isset($_SESSION['created'])) $_SESSION['created'] = time();
2011-02-12 01:25:15 -05:00
if(!isset($_COOKIE[$config['cookies']['hash']]) || !isset($_COOKIE[$config['cookies']['time']]) || $_COOKIE[$config['cookies']['hash']] != md5($_COOKIE[$config['cookies']['time']] . $config['cookies']['salt'])) {
2010-11-02 06:57:33 -04:00
$time = time();
2011-02-12 01:25:15 -05:00
setcookie($config['cookies']['time'], $time, time()+$config['cookies']['expire'], $config['cookies']['jail']?$config['root']:'/', null, false, true);
setcookie($config['cookies']['hash'], md5($time . $config['cookies']['salt']), $time+$config['cookies']['expire'], $config['cookies']['jail']?$config['root']:'/', null, false, true);
2010-11-02 06:57:33 -04:00
$user = Array('valid' => false, 'appeared' => $time);
} else {
2011-02-12 01:25:15 -05:00
$user = Array('valid' => true, 'appeared' => $_COOKIE[$config['cookies']['time']]);
2010-11-02 06:57:33 -04:00
}
2010-12-01 05:24:14 -05:00
2010-11-02 06:57:33 -04:00
?>