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 php man:
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.
From there I did some php (simplified here):
// PAGE1.PHP
session_start();
$_SESSION['test'] = true;
echo "sid=" . session_id();
// PAGE2.PHP
session_start();
if ($_SESSION['test'])
$echo "success";
else
$echo "fail";
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
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);
}
I have tried via POST and GET method and it doesn't seem to work.
So I'm wondering if it's possible, and if yes, what do I miss?
thanks.