This repository has been archived by the owner on Feb 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·89 lines (71 loc) · 2.1 KB
/
functions.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
include_once('config.php');
function ReturnNum ($value){
// Evaluates the value to ensure it is numeric and if not returns a 0
if (! is_numeric($value)) {
$value = 0;
}
return $value;
}
function ReturnString ($value){
// Evaluates the value to ensure it is not a few values and if it is returns a blank string
if (!strcmp($value,"-")){
$value = "";
} elseif (!strcmp($value, "(empty)")){
$value = "";
} elseif (strpos($value, "'") !== false) {
$value = addslashes($value);
}
return $value;
}
function db_connect() {
// Define connection as a static variable, to avoid connecting more than once
static $connection;
// Try and connect to the database, if a connection has not been established yet
if(!isset($connection)) {
// Load configuration as an array. Use the actual location of your configuration file
$connection = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
}
// If connection was not successful, handle the error
if($connection === false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return mysqli_connect_error();
}
return $connection;
}
function db_query($query) {
// Connect to the database
$connection = db_connect();
// Query the database
$result = mysqli_query($connection,$query);
return $result;
}
function num_rows($query) {
// Connect to the database
$connection = db_connect();
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($connection, $query)) {
/* determine number of rows result set */
$row_cnt = mysqli_num_rows($result);
/* close result set */
mysqli_free_result($result);
}
return $row_cnt;
}
function is_ip($str) {
$ret = filter_var($str, FILTER_VALIDATE_IP);
return $ret;
}
function is_ipv4($str) {
$ret = filter_var($str, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
return $ret;
}
function is_ipv6($str) {
$ret = filter_var($str, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
return $ret;
}
?>