snipt

Ctrl+h for KB shortcuts

PHP

iPhone user agent

1
2
3
4
5
6
7
$is_iphone = ((strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "iphone") !== false) || (strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "ipod") !== false));
 $is_bberry = (strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "blackberry") !== false);
 $is_nokia = (strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "series60") !== false);
 $is_pre = (strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "pre/") !== false || strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "webos/") !== false);
 $is_mobile = ($is_iphone || $is_bberry || $is_pre || $is_nokia || strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "iemobile") !== false || strpos(lowerTrim($_SERVER["HTTP_USER_AGENT"]), "blazer") !== false);

// later you can use <? if $is_iphone ?> blah blah <? endif; ?>
https://snipt.net/embed/2a2926e808cf61699d1f3660d6864de9/
/raw/2a2926e808cf61699d1f3660d6864de9/
2a2926e808cf61699d1f3660d6864de9
php
PHP
7
2019-08-13T01:15:33
True
False
False
/api/public/snipt/13811/
iphone-user-agent
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">$is_iphone = ((strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;iphone&quot;) !== false) || (strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;ipod&quot;) !== false));</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> $is_bberry = (strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;blackberry&quot;) !== false);</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> $is_nokia = (strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;series60&quot;) !== false);</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> $is_pre = (strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;pre/&quot;) !== false || strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;webos/&quot;) !== false);</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> $is_mobile = ($is_iphone || $is_bberry || $is_pre || $is_nokia || strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;iemobile&quot;) !== false || strpos(lowerTrim($_SERVER[&quot;HTTP_USER_AGENT&quot;]), &quot;blazer&quot;) !== false);</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="x">// later you can use </span><span class="cp">&lt;?</span> <span class="k">if</span> <span class="nv">$is_iphone</span> <span class="cp">?&gt;</span><span class="x"> blah blah </span><span class="cp">&lt;?</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
device, php