<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ideawaza.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=125.22.158.0%2F24</id>
	<title>IdeaWazaWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://ideawaza.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=125.22.158.0%2F24"/>
	<link rel="alternate" type="text/html" href="https://ideawaza.com/wiki/Special:Contributions/125.22.158.0/24"/>
	<updated>2026-09-29T22:27:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://ideawaza.com/index.php?title=Archive:PHP_and_MySQL_Programming/Session_Handling&amp;diff=42682</id>
		<title>Archive:PHP and MySQL Programming/Session Handling</title>
		<link rel="alternate" type="text/html" href="https://ideawaza.com/index.php?title=Archive:PHP_and_MySQL_Programming/Session_Handling&amp;diff=42682"/>
		<updated>2006-06-06T06:57:44Z</updated>

		<summary type="html">&lt;p&gt;125.22.158.128: /* Destroying a Session */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Programming:PHP and MySQL|TOC]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
HTML and PHP are &amp;quot;stateless&amp;quot; languages. Meaning that they are incapable of retaining a state between pages. To get around this serious limitation, we use Sessions. With sessions, session variables are stored in a file on the web server and so are accessible across multiple pages.&lt;br /&gt;
&lt;br /&gt;
== Starting a Session ==&lt;br /&gt;
&lt;br /&gt;
Before we can start using session variables, we need to start a session. This needs to be done on every page that makes use of session variables. It is important to note that a session must be started BEFORE ANYTHING IS OUTPUTED. Here is the code to start a session :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please make sure that there are NO SPACES before the &amp;quot;&amp;lt;?&amp;quot; (php starting tag), as that will return errors!&lt;br /&gt;
&lt;br /&gt;
It is worth noting, that the way in which the server distinguishes between multiple sessions being implemented on it simultaneously is by session ID&#039;s. When a unique session is created, it is assigned a Session ID, which the browser retains, and is used to let the we server know which session to use.&lt;br /&gt;
&lt;br /&gt;
== Writing Session Variables ==&lt;br /&gt;
&lt;br /&gt;
Once a session is created, variables may be stored in the $_SESSION[] array variable. Here is an example :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 $_SESSION[&#039;user_name&#039;] = &amp;quot;Administrator&amp;quot;;&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Retrieving Session Variables ==&lt;br /&gt;
&lt;br /&gt;
Once a session is created, and variables are stored, they may be retrieved from the $_SESSION[] array. Here is an example :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 if (isset($_SESSION[&#039;user_name&#039;])){&lt;br /&gt;
    $user_name = $_SESSION[&#039;user_name&#039;];&lt;br /&gt;
    print $user_name;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example starts a session, then checks if the session variable &#039;user_name&#039; has been created (with the isset() function), if it has, then it assigns its value to $user_name, and prints it to the screen.&lt;br /&gt;
&lt;br /&gt;
== Destroying a Session ==&lt;br /&gt;
&lt;br /&gt;
To destroy a session, we use the session_destroy() function. This is useful if we want to, for example, log a user off of a web-application. Thus we would use the following code :&lt;br /&gt;
&lt;br /&gt;
 logoff.php&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 session_destroy();&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we first need to start the session before we destroy it. This is because the session_destroy() function destroys the currently active session.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Programming:PHP and MySQL:Database Connectivity|&amp;lt;&amp;lt; 4. Database Connectivity]] | [[Programming:PHP and MySQL|TOC]] | [[Programming:PHP and MySQL:Command Line Programming|&amp;gt;&amp;gt; 6. Command Line Programming]]&lt;/div&gt;</summary>
		<author><name>125.22.158.128</name></author>
	</entry>
	<entry>
		<id>https://ideawaza.com/index.php?title=Archive:PHP_and_MySQL_Programming/Session_Handling&amp;diff=42681</id>
		<title>Archive:PHP and MySQL Programming/Session Handling</title>
		<link rel="alternate" type="text/html" href="https://ideawaza.com/index.php?title=Archive:PHP_and_MySQL_Programming/Session_Handling&amp;diff=42681"/>
		<updated>2006-06-06T06:54:27Z</updated>

		<summary type="html">&lt;p&gt;125.22.158.128: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Programming:PHP and MySQL|TOC]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
HTML and PHP are &amp;quot;stateless&amp;quot; languages. Meaning that they are incapable of retaining a state between pages. To get around this serious limitation, we use Sessions. With sessions, session variables are stored in a file on the web server and so are accessible across multiple pages.&lt;br /&gt;
&lt;br /&gt;
== Starting a Session ==&lt;br /&gt;
&lt;br /&gt;
Before we can start using session variables, we need to start a session. This needs to be done on every page that makes use of session variables. It is important to note that a session must be started BEFORE ANYTHING IS OUTPUTED. Here is the code to start a session :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please make sure that there are NO SPACES before the &amp;quot;&amp;lt;?&amp;quot; (php starting tag), as that will return errors!&lt;br /&gt;
&lt;br /&gt;
It is worth noting, that the way in which the server distinguishes between multiple sessions being implemented on it simultaneously is by session ID&#039;s. When a unique session is created, it is assigned a Session ID, which the browser retains, and is used to let the we server know which session to use.&lt;br /&gt;
&lt;br /&gt;
== Writing Session Variables ==&lt;br /&gt;
&lt;br /&gt;
Once a session is created, variables may be stored in the $_SESSION[] array variable. Here is an example :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 $_SESSION[&#039;user_name&#039;] = &amp;quot;Administrator&amp;quot;;&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Retrieving Session Variables ==&lt;br /&gt;
&lt;br /&gt;
Once a session is created, and variables are stored, they may be retrieved from the $_SESSION[] array. Here is an example :&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 if (isset($_SESSION[&#039;user_name&#039;])){&lt;br /&gt;
    $user_name = $_SESSION[&#039;user_name&#039;];&lt;br /&gt;
    print $user_name;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example starts a session, then checks if the session variable &#039;user_name&#039; has been created (with the isset() function), if it has, then it assigns its value to $user_name, and prints it to the screen.&lt;br /&gt;
&lt;br /&gt;
== Destroying a Session ==&lt;br /&gt;
&lt;br /&gt;
To destroy a session, we use the session_destroy() function. This is useful if we want to, for example, log a user off of a web-application. Thus we would use the following code :&lt;br /&gt;
&lt;br /&gt;
 logoff.php&lt;br /&gt;
 &amp;lt;?&lt;br /&gt;
 session_start();&lt;br /&gt;
 session_destroy();&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we first need to start the session before we destory it. This is because the session_destroy() function destroys the currently active session.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Programming:PHP and MySQL:Database Connectivity|&amp;lt;&amp;lt; 4. Database Connectivity]] | [[Programming:PHP and MySQL|TOC]] | [[Programming:PHP and MySQL:Command Line Programming|&amp;gt;&amp;gt; 6. Command Line Programming]]&lt;/div&gt;</summary>
		<author><name>125.22.158.128</name></author>
	</entry>
</feed>