snipt

Ctrl+h for KB shortcuts

PHP

detect iphone browser

1
2
3
4
< ?php
$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if ($browser == true)  { echo 'Code You Want To Execute'; }
?>
https://snipt.net/embed/94e9ef8d3e0da48dad0b4df25019e76b/
/raw/94e9ef8d3e0da48dad0b4df25019e76b/
94e9ef8d3e0da48dad0b4df25019e76b
php
PHP
4
2019-07-24T00:14:14
True
False
False
/api/public/snipt/25064/
detect-iphone-browser-1
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">&lt; ?php</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$browser = strpos($_SERVER[&#39;HTTP_USER_AGENT&#39;],&quot;iPhone&quot;);</span> </span><span id="L-3"><a name="L-3"></a><span class="x">if ($browser == true) { echo &#39;Code You Want To Execute&#39;; }</span> </span><span id="L-4"><a name="L-4"></a><span class="x">?&gt;</span> </span></pre></div> </td></tr></table>
browser, detect, iphone, php

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