-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
45 lines (38 loc) · 1.06 KB
/
function.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
<?php
function base_url()
{
if ($_SERVER['HTTP_HOST'] === 'localhost') {
$base_url = "http://localhost/edot-gypsum/";
} else {
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://" . $_SERVER['HTTP_HOST'];
$base_url .= "/";
}
return $base_url;
}
function base_url_admin()
{
return base_url() . 'admin/';
}
function cek_login()
{
if (!isset($_SESSION['id_admin'])) {
$admin = base_url_admin();
header("location:" . $admin . "login.php");
}
}
function generateUniqueCode()
{
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$code = '';
// Add current timestamp (UNIX timestamp) to the code
$timestamp = time();
$code .= strtoupper(base_convert($timestamp, 10, 36)); // Convert timestamp to base36
// Generate the remaining characters
$remainingLength = 16 - strlen($code);
for ($i = 0; $i < $remainingLength; $i++) {
$code .= $characters[rand(0, strlen($characters) - 1)];
}
return $code;
}
?>