forked from siwaonline/social_stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedirect.php
56 lines (49 loc) · 1.54 KB
/
Redirect.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
46
47
48
49
50
51
52
53
54
55
56
<?php
$http = isset($_SERVER['HTTPS']) ? "https" : "http";
$host = $_SERVER["HTTP_HOST"];
$request = $_SERVER["REQUEST_URI"];
$params = explode("?", $request)[1];
if ($params == "") {
$url = $http . "://" . $host . $_SERVER["REQUEST_URI"];
echo
'
<script>
var hash = window.location.hash;
if(hash == ""){
alert("Error");
}else{
var uri = "' . $url . '?"+hash.substring(1);
uri.replace("??","?");
window.location.replace(uri);
}
</script>';
} else {
$url = $http . "://" . $host . "/typo3/index.php?";
parse_str($params, $parts);
if (array_key_exists("state", $parts)) {
$state = $parts["state"];
$state = urldecode($state);
$state = str_replace(",", "&", $state);
$state = str_replace(get_string_between($state, "&P[returnUrl]=", "&P["), urlencode(get_string_between($state, "&P[returnUrl]=", "&P[")), $state);
$url .= $state;
}
if (array_key_exists("code", $parts)) {
$url .= "&code=" . $parts["code"];
}
if (array_key_exists("access_token", $parts)) {
$url .= "&access_token=" . $parts["access_token"];
}
if (array_key_exists("expires_in", $parts)) {
$url .= "&expires_in=" . $parts["expires_in"];
}
header('Location: ' . $url);
}
function get_string_between($string, $start, $end)
{
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}