snipt

Ctrl+h for KB shortcuts

PHP

check SSL and redirect to SSL if not

1
2
3
4
5
     if ($_SERVER['HTTPS'] != "on") {
    $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $url");
    exit;
}  
https://snipt.net/embed/ba9fe48af19d756ebbce3331afb3e4c2/
/raw/ba9fe48af19d756ebbce3331afb3e4c2/
ba9fe48af19d756ebbce3331afb3e4c2
php
PHP
5
2019-07-22T23:01:12
True
False
False
/api/public/snipt/24394/
check-ssl-and-redirect-to-ssl-if-not
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x"> if ($_SERVER[&#39;HTTPS&#39;] != &quot;on&quot;) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> $url = &quot;https://&quot;. $_SERVER[&#39;SERVER_NAME&#39;] . $_SERVER[&#39;REQUEST_URI&#39;];</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> header(&quot;Location: $url&quot;);</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> exit;</span> </span><span id="L-5"><a name="L-5"></a><span class="x">} </span> </span></pre></div> </td></tr></table>
php, redirect, ssl