Blog Details

Sessions


                                
                                    <h2>* PHP Sessions :-</h2>
<ul>
	<li>A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.</li>
	<li>Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.</li>
</ul>
<h2><strong>Storing a Session Variable :-</strong></h2>
&lt;?php
<strong>session_start();</strong>
// store session data
$_SESSION['views']=1;
?&gt;

&lt;html&gt;
&lt;body&gt;

&lt;?php
//retrieve session data
echo "Pageviews=".<strong> $_SESSION['views']</strong>;
?&gt;

&lt;/body&gt;
&lt;/html&gt;

&nbsp;
<h3>Output:</h3>
<div>Pageviews=1</div>
<div></div>
<div></div>
<h2><strong> Destroying a Session :-</strong></h2>
<ul>
	<li>If you wish to delete some session data, you can use the unset() or the session_destroy() function.</li>
	<li>The unset() function is used to free the specified session variable:</li>
</ul>
&lt;?php
<strong>session_start();</strong>
if(isset($_SESSION['views']))
unset($_SESSION['views']);
?&gt;
<ul>
	<li>You can also completely destroy the session by calling the session_destroy() function:</li>
</ul>
&lt;?php
<strong>session_destroy();</strong>
?&gt;

&nbsp;
                                    


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote