<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Spice World! &#187; PHP Sessions</title>
	<atom:link href="http://www.cyberspice.org.uk/blog/tag/php-sessions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cyberspice.org.uk/blog</link>
	<description>The life and times of a jet setting software engineer!</description>
	<lastBuildDate>Fri, 02 Dec 2011 14:52:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Using PHP sessions from Java</title>
		<link>http://www.cyberspice.org.uk/blog/2009/03/19/using-php-sessions-from-java/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/03/19/using-php-sessions-from-java/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 16:02:45 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[PHP Sessions]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=141</guid>
		<description><![CDATA[This blog post is the first in a number of what I hope are useful coding related posts. I&#8217;ve been coding for many years in many languages on many platforms. I tend to solve issues using a combination of technologies so many of my posts will be based around combining technologies. Others will be basically [...]]]></description>
			<content:encoded><![CDATA[<p>This blog post is the first in a number of what I hope are useful coding related posts.  I&#8217;ve been coding for many years in many languages on many platforms.  I tend to solve issues using a combination of technologies so many of my posts will be based around combining technologies.  Others will be basically describing gotchas that I have found during development and how I solved or worked around them.  This post is about using PHP&#8217;s session handling from a Java client, i.e. not a browser.</p>
<p><span id="more-141"></span></p>
<h3>PHP session handling</h3>
<p><a href="http://uk3.php.net/session">PHP session handling</a> is a way of having persistent or stateful data across HTTP requests.  The simplest snippet of PHP to achieve this is shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Start the session</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create a new session object if its a new session</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'session'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'session'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MySessionObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I tend to use a PHP class to encapsulate the session data.  Using the code above a new instance of <em>MySessionObject()</em> is created if a session could not be restored.  Otherwise the instance is restored from the previous time the code was called.</p>
<p>PHP actually manages this using a session ID stored in a cookie.  (There is an alternative method of managing the session ID if cookies are disable in a browser but that&#8217;s beyond the scope of this post.)  The <em>session_start()</em> call will parse the value of the <strong>Cookie:</strong> HTTP request header field looking for a value similar to <strong>PHPSESSID=b330c9b604d371e5c88cd0919990f41c</strong>.  It will use the session ID value to retrieve the appropriate session data.  It will deserialise any stored values and store them in the  <em>$_SESSION</em> global array variable.</p>
<p>If the <strong>PHPSESSID</strong> does not exist <em>session_start()</em> will create a new empty session (and <em>$_SESSION</em>) and use <strong>Set-Cookie:</strong> in the HTTP response to pass the session ID cookie to the browser so it can be returned on the next request.  The session cookie is valid for the lifetime of the browser.</p>
<h3>The Java client</h3>
<p>However this post is about using PHP sessions from Java.  To make an HTTP request from Java use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/HttpURLConnection.html"><em>HttpURLConnection</em></a> class.  This class does have a few gotchas which I will explain below but it is sufficient for our needs.  Typically I encapsulate the class in my own class to manage extra data.  The bones of such a class is as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyConnection <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> HTTP_HEADER_SET_COOKIE <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;set-cookie&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> cookies <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> MyConnection<span style="color: #009900;">&#40;</span><span style="color: #003399;">URL</span> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">url</span> <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> readCookies<span style="color: #009900;">&#40;</span><span style="color: #003399;">HttpURLConnection</span> con<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// ...</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> sendRequest<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> requestString<span style="color: #009900;">&#41;</span> 
		<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, SocketTimeoutException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// ...</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You create an instance of the class when you want to start communicating with the remote URL and it will store cookies between each communication session with the remote server.  The main work is carried out by the <em>sendRequest()</em> method which is shown below.</p>
<p><em>HttpURLConnection</em> is a little tricky to use due to the time at which the request is actually sent to the server.  If you set header fields (using <em>setRequestProperty()</em>) too late then they wont be included.  It is similar for other properties too.  </p>
<p>By default the class expects to have an empty body to the request sent to the server and returns the body of the response to the user by way of the input stream obtained using <em>getInputStream()</em>.  (Note that input and output here refers to data being input to the connection and output from the connection.  I.e. input in to the server and output from the server which may be the reverse of what you&#8217;re expecting.)  However you can tell the connection you intend providing a body to the request by calling <em>setDoOutput()</em> with a value of <strong>true</strong>.  In this case the output data is buffered and sent with the headers when <em>getInputStream()</em> is called.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> sendRequest<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> requestString<span style="color: #009900;">&#41;</span> 
	<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, SocketTimeoutException <span style="color: #009900;">&#123;</span>
&nbsp;
	StringBuilder buffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> line<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Get the connection.  Java will create a new one each time.</span>
	<span style="color: #003399;">HttpURLConnection</span> con <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">HttpURLConnection</span><span style="color: #009900;">&#41;</span>url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Set the Cookie header</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cookies <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		con.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cookie&quot;</span>, cookies<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Set the content-size header</span>
	con.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-size&quot;</span>, 
		<span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>requestString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Set the request method.</span>
	con.<span style="color: #006633;">setRequestMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;POST&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Enable both reading and writing to and from the connection.</span>
	con.<span style="color: #006633;">setDoInput</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	con.<span style="color: #006633;">setDoOutput</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Get the output stream</span>
	<span style="color: #003399;">OutputStreamWriter</span> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">OutputStreamWriter</span><span style="color: #009900;">&#40;</span>con.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Send the request</span>
	out.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>requestString.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	out.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Get the input stream.  This is the point at which data is sent to </span>
	<span style="color: #666666; font-style: italic;">// and read from the server.</span>
	<span style="color: #003399;">BufferedReader</span> in <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>
		<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>con.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// If the response from the server is OK handle the content of the response</span>
	<span style="color: #003399;">String</span> responseCode  <span style="color: #339933;">=</span> con.<span style="color: #006633;">getResponseCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseCode <span style="color: #339933;">==</span> <span style="color: #003399;">HttpURLConnection</span>.<span style="color: #006633;">HTTP_OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Read the cookies</span>
		<span style="color: #003399;">String</span> cookies <span style="color: #339933;">=</span> readCookies<span style="color: #009900;">&#40;</span>con<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cookies <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cookies</span> <span style="color: #339933;">=</span> cookies<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Read the content</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> in.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			buffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> buffer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Error from server</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Basically the method obtains a connection and sets up important headers, the request type, sends the request string as the body of the request returning the response string to the caller.  This is a fairly typical use of the <em>HttpURLConnection</em> class.  The important bit with respect to this particular post is the cookie handling.  </p>
<p>In the code above, if the <em>cookies</em> variable is set then it is passed to the server as the value of a <strong>Cookie:</strong> header otherwise that header is omitted.  When an instance of the <em>MyConnection</em> class is created the <em>cookies</em> variable is initialised to null and is only set when a <strong>Set-Cookie:</strong> header is received from the server.  This is handled by the <em>readCookies()</em> method.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> readCookies<span style="color: #009900;">&#40;</span><span style="color: #003399;">HttpURLConnection</span> con<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	StringBuilder cookieBuffer <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span>        cookieField  <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span>        headerName   <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>headerName <span style="color: #339933;">=</span> con.<span style="color: #006633;">getHeaderFieldKey</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>headerName.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>HTTP_HEADER_SET_COOKIE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			cookieField <span style="color: #339933;">=</span> con.<span style="color: #006633;">getHeaderField</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			cookieField <span style="color: #339933;">=</span> cookieField.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, 
				cookieField.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cookieBuffer <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				cookieBuffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				cookieBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			cookieBuffer.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>cookieField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cookieBuffer <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> cookieBuffer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Annoyingly there isn&#8217;t a getter equivalent to <em>setRequestProperty()</em>.  You can only obtain headers provided in the response by index.  This means that you have to iterate through all the headers looking for the ones your interested in.  This is slightly simplified by the <em>getHeaderFieldKey()</em> which returns the header name, for example, <strong>Set-Cookie</strong> for the specified index.  So you iterate through the header names obtaining the header data for each of the names you are interested.  The value of the cookie is everything up to the first semi-colon.  The rest is meta-data.</p>
<p>However nothing is simple in this world.  It appears that the Android version of <em>HttpURLConnection</em> converts the header field name to lower case but the Sun version (in the JDK) does not.  So above I convert the header name to lowercase before comparison to ensure I&#8217;m always comparing like with like.  </p>
<p>Yet another gotcha is that you could have more than one <strong>Set-Cookie</strong> header but you can only call <em>setRequestProperty()</em> once for each header.  If you call it more than once you overwrite the previous value.  So I concatenate all the cookies received in to one cookie string separating them appropriately.</p>
<p>So combining everything the Java client creates an instance of <em>MyConnection</em> with the appropriate URL.  When <em>sendRequest()</em> is first called no cookies are set.  The PHP on the server calls <em>session_start()</em> that creates a new session.  The session ID is returned to the Java client, obtained by <em>readCookies()</em> and stored in the instance of <em>MyConnection</em>.  </p>
<p>Subsequent calls to <em>sendRequest()</em> will return the session ID back to the PHP running on the server for as long as the instance of <em>MyConnection</em> exists.  This way creating a new instance of <em>MyConnection</em> creating a new session on the server automatically.</p>
<p>So that&#8217;s how you use PHP session from a Java client.  I hope this post is useful and welcome any comments about content or style.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/03/19/using-php-sessions-from-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

