-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.php
More file actions
68 lines (60 loc) · 1.28 KB
/
common.php
File metadata and controls
68 lines (60 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once "config.php";
function showlogin()
{
echo <<<EOD
<form id="login" action="login.php" method="post">
<label for="email">Email address:</label>
<input type="text" name="email"/><br/>
<label for="password">Password:</label>
<input type="password" name="password"/><br/>
<input type="submit" value="Log In"/>
</form>
<a href="adduser.php">Register</a>
EOD;
}
// login_mode: 0=don't show, 1=show, 2=force (default)
function myheader($title, $login_mode = 2) {
session_start();
echo <<<EOD
<html>
<head>
<title>$title</title>
</head>
<body>
EOD;
if (!isset($_SESSION['user']))
{
if ($login_mode > 0)
showlogin();
if ($login_mode == 2) {
myfooter();
exit();
}
}
}
function myfooter()
{
echo <<<EOD
</body>
</html>
EOD;
}
function dbconnect() {
if (!isset($GLOBALS['mysqli'])) {
$GLOBALS['mysqli'] = new mysqli($GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass'], $GLOBALS['dbname']);
if (mysqli_connect_errno())
die("Error connecting to database: " . mysqli_connect_error());
}
return $GLOBALS['mysqli'];
}
function budgetname($id)
{
$mysqli = dbconnect();
$q = $mysqli->query("select name from budgets where id = $id");
$r = $q->fetch_assoc();
$name = $r['name'];
$q->free_result();
return $name;
}
?>