snipt

Ctrl+h for KB shortcuts

PHP

Force Wordpress Admin Login Page to use SSL/HTTPS

1
2
3
4
5
6
7
8
<?php 
if(strstr($_SERVER["REQUEST_URI"],"/wp-login.php") && $_SERVER["HTTPS"] != "on") {
	$newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
	header("Location: $newurl");
	echo $newurl;
	exit();
}
?>
https://snipt.net/embed/1cd623503f4af3596ef9d5390b8f85fe/
/raw/1cd623503f4af3596ef9d5390b8f85fe/
1cd623503f4af3596ef9d5390b8f85fe
php
PHP
8
2019-08-17T23:08:37
True
False
False
Aug 15, 2012 at 10:31 AM
/api/public/snipt/45737/
force-wordpress-admin-login-page-to-use-sslhttps
<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> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nb">strstr</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;REQUEST_URI&quot;</span><span class="p">],</span><span class="s2">&quot;/wp-login.php&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;HTTPS&quot;</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">&quot;on&quot;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$newurl</span> <span class="o">=</span> <span class="s2">&quot;https://&quot;</span> <span class="o">.</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_NAME&quot;</span><span class="p">]</span> <span class="o">.</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;REQUEST_URI&quot;</span><span class="p">];</span> </span><span id="L-4"><a name="L-4"></a> <span class="nb">header</span><span class="p">(</span><span class="s2">&quot;Location: </span><span class="si">$newurl</span><span class="s2">&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="nv">$newurl</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">exit</span><span class="p">();</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
compliance, https, pci, redirect, ssl, wordpress