title: Using a session with php and Java
body: <p>I'm currently trying to use the current session of a php web page from an applet. I tought it would be straightforward, but it didn't go as smooth as I tough. From the <a href="http://www.php.net/manual/en/function.session-start.php" rel="nofollow noreferrer">php man</a>: </p>
  
  <pre><code>session_start() creates a session or resumes the current one based on a session
  identifier passed via a GET or POST request, or passed via a cookie.
  </code></pre>
  
  <p>From there I did some php (simplified here):</p>
  
  <pre><code>// PAGE1.PHP
  session_start();
  $_SESSION['test'] = true;
  echo "sid=" . session_id();
  
  // PAGE2.PHP
  session_start();
  if ($_SESSION['test'])
      $echo "success";
  else
      $echo "fail";
  </code></pre>
  
  <p>So, from my applet, I do a request to PAGE1.PHP and it returns me the session id. When I do a new request on the page 2, I pass the session id as a parameter and it seems that the session wasn't kept. I use </p>
  
  <pre><code>URL url = new URL("my/url/PAGE2.php?sid=" + session_id); 
  URLConnection conn = url.openConnection();
  conn.setDoOutput(true); 
  OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
  
  wr.write(data); // data is the post data created previously
  wr.flush(); 
  
  // Get the response 
  BufferedReader rd = new BufferedReader(
      new InputStreamReader(conn.getInputStream())); 
  String line;
  while ((line = rd.readLine()) != null) { 
      System.out.println(line);
  }
  </code></pre>
  
  <p>I have tried via POST and GET method and it doesn't seem to work. </p>
  
  <p>So I'm wondering if it's possible, and if yes, what do I miss?</p>
  
  <p>thanks.</p>