snipt

Ctrl+h for KB shortcuts

PHP

auto detect site_url

1
2
3
4
5
6
<?php

// auto detect base url
$site_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$site_url .= '://'. $_SERVER['HTTP_HOST'];
$site_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
https://snipt.net/embed/3d238f43ffa8a9abb02d6b1598a23ed8/
/raw/3d238f43ffa8a9abb02d6b1598a23ed8/
3d238f43ffa8a9abb02d6b1598a23ed8
php
PHP
6
2019-07-22T17:19:59
True
False
False
/api/public/snipt/57830/
auto-detect-site_url
<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></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><span id="L-3"><a name="L-3"></a><span class="c1">// auto detect base url</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$site_url</span> <span class="o">=</span> <span class="nb">isset</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTPS&#39;</span><span class="p">])</span> <span class="o">&amp;&amp;</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTPS&#39;</span><span class="p">])</span> <span class="o">!==</span> <span class="s1">&#39;off&#39;</span> <span class="o">?</span> <span class="s1">&#39;https&#39;</span> <span class="o">:</span> <span class="s1">&#39;http&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$site_url</span> <span class="o">.=</span> <span class="s1">&#39;://&#39;</span><span class="o">.</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTP_HOST&#39;</span><span class="p">];</span> </span><span id="L-6"><a name="L-6"></a><span class="nv">$site_url</span> <span class="o">.=</span> <span class="nb">str_replace</span><span class="p">(</span><span class="nb">basename</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;SCRIPT_NAME&#39;</span><span class="p">]),</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;SCRIPT_NAME&#39;</span><span class="p">]);</span> </span></pre></div> </td></tr></table>
auto, base_url, detect, site_url

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