From b2d61ea343e965a5abb5a5adf151431dd659314b Mon Sep 17 00:00:00 2001 From: Ezequiel Villarreal Date: Fri, 22 Apr 2016 07:48:13 -0500 Subject: [PATCH] Current Protocol (Helper) Hello. I have this method to get the current protocol in every project, some with http,other with https. I made this method to help me identify better which protocol is present in my project so I can use properly http or https in my links. I don't know if there exists something that do the same thing, but I searched and found nothing. Hope this helps or maybe if you don't want it in main class you can put it in a helper class like I did. I extended Kohana_HTTP. --- classes/Kohana/HTTP.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/classes/Kohana/HTTP.php b/classes/Kohana/HTTP.php index 4c22c52bc..fe23b0c34 100644 --- a/classes/Kohana/HTTP.php +++ b/classes/Kohana/HTTP.php @@ -220,5 +220,24 @@ public static function www_form_urlencode(array $params = array()) return implode('&', $encoded); } + + public static function current_protocol() + { + $protocol = Request::$initial; + + if ($protocol instanceof Request) + { + if ($protocol->secure()) + $protocol = 'https'; + else + list($protocol) = explode('/', strtolower($protocol->protocol())); + } + else + { + $protocol = 'http'; + } + + return $protocol; + } }