snipt

Ctrl+h for KB shortcuts

PHP

Show different Div's based on cookies

1
2
3
4
5
6
7
8
<?php
if(isset($_COOKIE['div'])){
echo "<div>I can tell you've been here before</div>";
} else {
setcookie('div', true, 5184000 + time()); //hold fo 2 months
echo "<div>Its your first time being here</div>";
}
?> 
https://snipt.net/embed/3bbc08bdb01073b739fbb3e4b0d59721/
/raw/3bbc08bdb01073b739fbb3e4b0d59721/
3bbc08bdb01073b739fbb3e4b0d59721
php
PHP
8
2019-08-18T21:12:16
True
False
False
Jul 02, 2014 at 07:26 PM
/api/public/snipt/48009/
show-different-divs-based-on-cookies
<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">isset</span><span class="p">(</span><span class="nv">$_COOKIE</span><span class="p">[</span><span class="s1">&#39;div&#39;</span><span class="p">])){</span> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="s2">&quot;&lt;div&gt;I can tell you&#39;ve been here before&lt;/div&gt;&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> <span class="k">else</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a><span class="nb">setcookie</span><span class="p">(</span><span class="s1">&#39;div&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="mi">5184000</span> <span class="o">+</span> <span class="nb">time</span><span class="p">());</span> <span class="c1">//hold fo 2 months</span> </span><span id="L-6"><a name="L-6"></a><span class="k">echo</span> <span class="s2">&quot;&lt;div&gt;Its your first time being here&lt;/div&gt;&quot;</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>
cookies, php