I'm currently trying to use the current php webpage session from an applet. I would say that it would be simple, but it was not as smooth as me. From 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 made a few php (simplified here):
session_start();
$_SESSION['test'] = true;
echo "sid=" . session_id();
session_start();
if ($_SESSION['test'])
$echo "success";
else
$echo "fail";
So, from my applet, I make a request to PAGE1.PHP and return me the session identifier. When I make a new request on page 2, I pass the session identifier as a parameter, and it seems that the session was not saved. 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);
wr.flush();
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
I tried using the POST and GET method and it does not seem to work.
So I wonder if this is possible, and if so, what will I miss?
thank.
source
share