Skip to content

Commit 9af8925

Browse files
committed
Merge pull request #5 from mbrodala/patch-1
[BUGFIX] Keep current protocol on redirects
2 parents 2847863 + 7bfdd13 commit 9af8925

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cooluri/link.Functions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,14 @@ public static function redirect($path,$status=0) {
238238
$path = dirname($_SERVER['PHP_SELF']).'/'.$path;
239239
}
240240
$path = preg_replace('~^/~','',$path);
241-
$path = 'http://'.$_SERVER['HTTP_HOST'].'/'.$path;
241+
$path = preg_replace('~^/~','',$path);
242+
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
243+
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
244+
$protocol = 'https';
245+
} else {
246+
$protocol = 'http';
247+
}
248+
$path = $protocol . '://'.$_SERVER['HTTP_HOST'].'/'.$path;
242249
}
243250
if (!empty($status)) {
244251
header('Location: '.$path,true,$status);

0 commit comments

Comments
 (0)