Help for PHP java bridge [Very Urgent]

Alles, was PHP betrifft, kann hier besprochen werden.

Help for PHP java bridge [Very Urgent]

Postby reena_b » 06. February 2008 09:46

Hi,

I am new to php. i need your help to pass the session value from php to jsp or java

I have an login and logout page in php. I have to pass the session value from login to welcome page of jsp

Thanks in advance

Reena
reena_b
 
Posts: 2
Joined: 06. February 2008 09:31

Postby Scory » 06. February 2008 14:16

>I have to pass the session value from login to welcome page of jsp

As Session Variables are not part of the http Protocoll, you cannot simply pass the value from one page to another.

You should redirect from the php Script to the jsp-Script and supply the values of the session via GET (i.e. via URL). An example script may look this way:

Code: Select all
<?php

      session_start();

      /* For example, we have a session with three important data field: user, password und nickname.

     $user = $_SESSION['user'];
     $password = $_SESSION['password'];
     $nickname = $_SESSION['nickname'];

     /* Now we redirect to JSP Script and supply variables via URL: */

    header("Location: http://www.domain.com/script.jsp?user=$user&password=$password&nickname=$nickname");

    exit();
?>


Inside the script.jsp, you have to evaluate the values of the request-Variables 'user', 'password' and 'nickname'. As I dont know basic syntax of JSP, I cannot show you how to evaluate these request variables, but I am pretty sure, that this is in fact very easy.
Scory
 

Postby reena_b » 07. February 2008 05:09

Hi Scory,

Thanks for your reply. Sorry i forgot to mention that the id should not pass via URL.

I have a login and logout pages are in php. i have to pass the user id or the session to my jsp page.

The id should not pass in the url for security purpose and also the browser back button should not work if i click the logout.php
reena_b
 
Posts: 2
Joined: 06. February 2008 09:31

Postby sari42 » 07. February 2008 12:32

I have an login and logout page in php. I have to pass the session value from login to welcome page of jsp

my q&d suggestion:
Code: Select all
<?php
session_name('jsp');
session_start();
//... login stuff ...

$_SESSION['user'] = 'test'; // sanitized($_POST['user']);

//process auth($_POST['pw']) here already?
$_SESSION['authenticated'] = 1;

//... end login stuff ...

session_write_close(); //write to disk

header('Location: login_followup.jsp?SID=' . session_id());
// or header('Location: login_followup.jsp');
// and pickup the session_id from the 'jsp' cookie later
?>


The login_followup.jsp file then GETs the session id "SID" from the query string (or from the 'jsp' cookie) and picks
the data from 'whereeverPhpStoresSessionFiles/sess_' plus GET[SID] (dunno jsp syntax)
The content of the "sess_c5a1....." txt file then will be:
Code: Select all
user|s:4:"test";authenticated|i:1;

which can easily be split up.

Or - especially if the "login_followup.jsp" is on a remote box - use a php database session handler.

HTH
Last edited by sari42 on 07. February 2008 13:16, edited 3 times in total.
sari42
 
Posts: 800
Joined: 27. November 2005 18:28

Postby Scory » 07. February 2008 12:57

Or (most simple) write the desired data into any file (or database) and read it with jsp-Script.

I would *not* recommend to use the "original php session files", because you dont have the data format under your own control and if the format changes (for any reason), your programs will fail.
Scory
 


Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest