Last active
June 28, 2020 03:58
-
-
Save zdev0x/f0b59f6c37bc671f788b835c2a673102 to your computer and use it in GitHub Desktop.
convert-url-proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * convert or add url proto | |
| * @param [type] $url [description] | |
| * @param boolean $follow [description] | |
| * @return [type] [description] | |
| */ | |
| function convertUrlProto($url, $follow = true) | |
| { | |
| if ($follow && isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && !empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { | |
| $urlProto = $_SERVER['HTTP_X_FORWARDED_PROTO']; | |
| if (strpos($url, 'http://') === 0) { | |
| $url = $urlProto . '://' . substr($url, 7); | |
| } elseif (strpos($url, 'https://') === 0) { | |
| $url = $urlProto . '://' . substr($url, 8); | |
| } elseif (strpos($url, '//') === 0) { | |
| $url = $urlProto . ':' . $url; | |
| } else { | |
| $url = $urlProto . '://' . $url; | |
| } | |
| } | |
| return $url; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment