Passed
Push — master ( c862a9...ab6497 )
by William
02:35
created

logged-in-user.php ➔ ip_is_private()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
function ip_is_private() {
4
    $safe_ip = array(
5
        '194.82.168.3', //Canterbury
6
        '194.82.171.2', //Sheppey
7
        '195.194.248.2', //Broadstairs
8
        '', //Dover
9
        '195.194.250.2', //Folkstone
10
    );
11
12
    if (in_array($_SERVER['REMOTE_ADDR'], $safe_ip)) {
13
        return true;
14
    } else {
15
        return false;
16
    }
17
}
18
19
$u = new User();
20
global $u;
21
22
if ($u->isLoggedIn()) {
23
    echo '<p class="welcome-username">Welcome ' . $u->getUserName() . '</p>';
24
} else {
25
    echo '<p class="welcome-username"><a href="/login">Click here to Login</a></p>';
26
27
    $page = Page::getCurrentPage();
28
29
    if ($page->getCollectionName() == 'Home') {
30
31
        $ip = $_SERVER['REMOTE_ADDR'];
32
        if (ip_is_private() === FALSE) {
33
            header('Location: /login');
34
            die();
35
        }
36
    }
37
}
38
if ($u->inGroup(Group::getByName('Students'))) {
39
    header('Location: /dashboard/permissions');
40
    die();
41
}
42
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
43