-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_redir.php
41 lines (34 loc) · 1.11 KB
/
test_redir.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
<?php
if (isset($_GET['done']) and $_GET['done'] == 1) {
echo 'done';
die;
}
// Redirect to full self URL.
$scheme = 'http';
if (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') !== 0) {
$scheme = 'https';
}
$testurl = $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['SCRIPT_NAME'];
// Determine if we require the final redirect to be an external destination.
$extdest = isset($_GET['extdest']) ? '&extdest=' . $_GET['extdest'] : '';
$redir = isset($_GET['redir']) ? (int)$_GET['redir'] : 5;
if ($redir > 10) {
$redir = 10;
}
if ($redir <= 1) {
// If we need an external final destination, use moodle.com.
if (!empty($_GET['extdest'])) {
$target = 'https://moodle.com';
} else {
// If no external destination is required, set the target as the standard 'done' URL.
$target = "$testurl?done=1";
}
} else {
$redir--;
$target = "{$testurl}?redir={$redir}{$extdest}";
}
header('HTTP/1.1 302 Found');
header("Location: $target");
if ($_GET['verbose'] ?? false) {
echo "You will be shortly redirected to {$target}";
}