-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
69 lines (55 loc) · 1.91 KB
/
common.php
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
error_reporting(E_ALL);
//for production
//error_reporting(0); ini_set('display_errors','0');
require_once 'config.php';
$username=$fullname="";
if (isset($_SESSION["username"])) {
$username = $_SESSION["username"];
}
if (isset($_SESSION["fullname"])) {
$fullname = $_SESSION["fullname"];
}
//header("Content-Type: text/html; charset=utf-8");
//Checking User not Logged in. No. This cannot be in common.php as it makes an infinite loop in index.php (which requires common.php)
//if(empty($_SESSION['username'])){
// header("location:index.php");
//}
function connectToDB() {
// $servername = getenv('IP');
// $servername = "localhost";
$db = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
if ($db->connect_errno) {
echo "<script>";
echo 'alert("Error connecting to database '.$database.'. Your connection has probably timed out. Please log in again");';
echo "window.location='index.php';";
echo "</script>";
// header("Location: index.php");
# echo "Failed to connect to MySQL database $database : " . mysqli_connect_error();
# die("Program terminated");
}
//mysqli_query($db, "set names UTF8;");
return $db;
}
function runSimpleQuery($mysqli, $sql_) {
$result = mysqli_query($mysqli, $sql_);
// if (!$mysqli->error) {
// printf("Errormessage: %s\n", $mysqli->error);
// }
// Check result. This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message_ = 'Invalid query: ' . mysqli_error($mysqli) . "\n<br>";
$message_ .= 'SQL: ' . $sql_;
die($message_);
}
return $result;
}
function clean_html($string) {
$string = trim(htmlspecialchars(addslashes($string)));
#$string = trim(htmlentities(addslashes($string)));
return $string;
}
function clean_input($string) {
$string = trim(strip_tags(addslashes($string)));
return $string;
}