Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

C#

C# Session Check

1
2
3
4
5
6
if (Session["YourVar"] != null) {
// Do something here...

} else {
	// Do something else here...    
}
https://snipt.net/embed/7d6411ef7c8d2aa03d5824a628d8a82e/
https://snipt.net/raw/7d6411ef7c8d2aa03d5824a628d8a82e/
7d6411ef7c8d2aa03d5824a628d8a82e
csharp
C#
6
2016-12-05T16:42:10
True
False
False
/api/public/snipt/56136/
c-session-check
<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="k">if</span> <span class="p">(</span><span class="n">Session</span><span class="p">[</span><span class="s">&quot;YourVar&quot;</span><span class="p">]</span> <span class="p">!=</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// Do something here...</span> </span><span id="L-3"><a name="L-3"></a> </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="c1">// Do something else here... </span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
"session null", c#, session

PHP

Zend Auth Custon namspace

1
2
3
4
5
6
7
8
//if you have multiple projects on the same host, you need to specify the zend auth session namespace

<?php
$this->auth = Zend_Auth::getInstance();
$this->auth->setStorage(new Zend_Auth_Storage_Session('Test_User'));
//if (!$this->auth->hasIdentity()) {
//    $this->_redirector->gotoUrl('/entry');
//}
https://snipt.net/embed/ea190294ff4856acef5b41f624aae57e/
https://snipt.net/raw/ea190294ff4856acef5b41f624aae57e/
ea190294ff4856acef5b41f624aae57e
php
PHP
8
2016-12-02T16:51:02
True
False
False
Feb 06, 2013 at 03:09 AM
/api/public/snipt/55283/
zend-auth-custon-namspace
<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="x">//if you have multiple projects on the same host, you need to specify the zend auth session namespace</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="cp">&lt;?php</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">auth</span> <span class="o">=</span> <span class="nx">Zend_Auth</span><span class="o">::</span><span class="na">getInstance</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">auth</span><span class="o">-&gt;</span><span class="na">setStorage</span><span class="p">(</span><span class="k">new</span> <span class="nx">Zend_Auth_Storage_Session</span><span class="p">(</span><span class="s1">&#39;Test_User&#39;</span><span class="p">));</span> </span><span id="L-6"><a name="L-6"></a><span class="c1">//if (!$this-&gt;auth-&gt;hasIdentity()) {</span> </span><span id="L-7"><a name="L-7"></a><span class="c1">// $this-&gt;_redirector-&gt;gotoUrl(&#39;/entry&#39;);</span> </span><span id="L-8"><a name="L-8"></a><span class="c1">//}</span> </span></pre></div> </td></tr></table>
namespace, php, session, zend

VB.net

VB.Net Check for an Empty Session Variable

1
2
3
4
5
If Session("YourVar") Is Nothing Then
    ' Do something here...
Else
    ' Do something else here...
End If
https://snipt.net/embed/3271f2998c72fc676a03bf630502573f/
https://snipt.net/raw/3271f2998c72fc676a03bf630502573f/
3271f2998c72fc676a03bf630502573f
vb.net
VB.net
5
2016-12-05T12:04:09
True
False
False
/api/public/snipt/49344/
vbnet-check-for-an-empty-session-variable
<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="k">If</span> <span class="n">Session</span><span class="p">(</span><span class="s">&quot;YourVar&quot;</span><span class="p">)</span> <span class="ow">Is</span> <span class="k">Nothing</span> <span class="k">Then</span> </span><span id="L-2"><a name="L-2"></a> <span class="c">&#39; Do something here...</span> </span><span id="L-3"><a name="L-3"></a><span class="k">Else</span> </span><span id="L-4"><a name="L-4"></a> <span class="c">&#39; Do something else here...</span> </span><span id="L-5"><a name="L-5"></a><span class="k">End</span> <span class="k">If</span> </span></pre></div> </td></tr></table>
"session null", session, vb.net
Copyrighted, illegal, or inappropriate content? Email [email protected].