Test Failed
Push — main ( 82933d...ebe982 )
by Rafael
02:28
created

getIfIsset()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2024       Rafael San José         <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 * or see https://www.gnu.org/
18
 */
19
20
/**
21
 * Obtains the main url
22
 *
23
 * @return string
24
 */
25
function getUrl()
26
{
27
    $ssl = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on';
28
    $proto = strtolower($_SERVER['SERVER_PROTOCOL']);
29
    $proto = substr($proto, 0, strpos($proto, '/')) . ($ssl ? 's' : '');
30
    if (isset($_SERVER['HTTP_HOST'])) {
31
        $host = $_SERVER['HTTP_HOST'];
32
    } else {
33
        $port = $_SERVER['SERVER_PORT'];
34
        $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;
35
        $host = $_SERVER['SERVER_NAME'] . $port;
36
    }
37
38
    $script = $_SERVER['SCRIPT_NAME'];
39
40
    $script = substr($script, 0, strlen($script) - strlen('/index.php'));
41
    return $proto . '://' . $host . $script;
42
}
43
44
/**
45
 * This function is used to obtain the value of a POST variable, and if it does not exist
46
 * (for example, the first time the form is loaded), take a default value.
47
 *
48
 * @param $postVar
49
 * @param $defaultValue
50
 * @return mixed
51
 */
52
function getIfIsset($postVar, $defaultValue)
53
{
54
    $return = filter_input(INPUT_POST, $postVar);
55
    if ($return === null || $return === false) {
56
        return $defaultValue;
57
    }
58
    return $return;
59
}
60