-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
72 lines (53 loc) · 1.34 KB
/
functions.php
File metadata and controls
72 lines (53 loc) · 1.34 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
69
70
71
72
<?php
include_once('./HTMLElement.php');
include_once('./Form.php');
function get_random_string($length){
$a = "abcdefghijklmksjfhscrh3498324734";
$random_str = '';
for($i = 0; $i < $length; $i++){
$position = rand(0, strlen($a) - 1);
//$random_str .= substr($a, $position, 1);
$random_str .= $a[$position];
}
return $random_str;
}
function load_view($file, $data = []){
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
/**
* Get difference between 2 dates in years
* @param string $start_date in the format yyyy-mm-dd
* @param string $end_date in the format yyyy-mm-dd
* @return number of years or false on error
*/
function get_age_years($start_date, $end_date){
$start_ts = strtotime($start_date);
$end_ts = strtotime($end_date);
$diff = $end_ts - $start_ts;
return round($diff / 60 / 60 / 24 / 365.25, 0);
}
function get_username(){
static $username;
if(isset($username)) return $username;
// db query to get username
sleep(5);
$username = 'Amgad';
return $username;
}
function db_connect(){
static $link;
if(isset($link)) return $link;
include('./config.php');
// $host, $user, $pass, $db
// step 1 & 2: connect to server and select db
$link = @mysqli_connect($host, $user, $pass, $db);
if(!$link){
echo mysqli_connect_error();
die;
}
return $link;
}