Created
June 20, 2017 04:36
-
-
Save qwersk/344d46f1351396764ce3fb2ed2671403 to your computer and use it in GitHub Desktop.
GET CURRENT URL #PHP
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
| function request_url() | |
| { | |
| $result = ''; // Пока результат пуст | |
| $default_port = 80; // Порт по-умолчанию | |
| // А не в защищенном-ли мы соединении? | |
| if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']=='on')) { | |
| // В защищенном! Добавим протокол... | |
| $result .= 'https://'; | |
| // ...и переназначим значение порта по-умолчанию | |
| $default_port = 443; | |
| } else { | |
| // Обычное соединение, обычный протокол | |
| $result .= 'http://'; | |
| } | |
| // Имя сервера, напр. site.com или www.site.com | |
| $result .= $_SERVER['SERVER_NAME']; | |
| // А порт у нас по-умолчанию? | |
| if ($_SERVER['SERVER_PORT'] != $default_port) { | |
| // Если нет, то добавим порт в URL | |
| $result .= ':'.$_SERVER['SERVER_PORT']; | |
| } | |
| // Последняя часть запроса (путь и GET-параметры). | |
| $result .= $_SERVER['REQUEST_URI']; | |
| // Уфф, вроде получилось! | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment