Vanilla commit.
[tinybbs.git] / includes / header.php
blob8c53b4e938345098c7bbf942a4e20a0aabe40e63
1 <?php
3 require('config.php');
4 require('functions.php');
6 date_default_timezone_set('UTC');
7 header('Content-Type: text/html; charset=UTF-8');
8 session_cache_limiter('nocache');
9 session_name('SID');
10 session_start();
12 // Connect to the database.
13 $link = new mysqli($db_info['server'], $db_info['username'], $db_info['password'], $db_info['database']);
14 if (mysqli_connect_errno())
16 exit('<p>Unable to establish a connection to the database. ;_;</p>');
19 // Assume that we have no privileges.
20 $moderator = false;
21 $administrator = false;
23 // If necessary, assign the client a new ID.
24 if(empty($_COOKIE['UID']))
26 create_id();
28 else if( ! empty($_COOKIE['password']))
30 // Log in those who have just began their session.
31 if( ! isset($_SESSION['ID_activated']))
33 activate_id();
36 // ...and check for mod/admin privileges from the cache.
37 if(in_array($_SESSION['UID'], $moderators))
39 $moderator = true;
41 else if(in_array($_SESSION['UID'], $administrators))
43 $administrator = true;
47 // Start buffering shit for the template.
48 ob_start();
50 // Get visited topics from cookie.
51 $visited_cookie = explode('t', $_COOKIE['topic_visits']);
52 $visited_topics = array();
53 foreach($visited_cookie as $topic_info)
55 if(empty($topic_info))
57 continue;
59 list($cur_topic_id, $num_replies) = explode('n', $topic_info);
60 $visited_topics[$cur_topic_id] = $num_replies;
63 // Get most recent actions to see if there's anything new
64 $result = $link->query('SELECT feature, time FROM last_actions');
65 $last_actions = array();
66 while($row = $result->fetch_assoc())
68 $last_actions[$row['feature']] = $row['time'];