PHP Tutorial : Get Protocol

I saw this problem/question on a few forums and I finded it useful to post on my blog too due to low results on google that gives you what you need. So,  how to get the protocol of a URL using php?  Have a look :

<?php
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'?'https':'http';

print "The protocol is $protocol";
?>

Tadaaa!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>