Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

PHP to Java

 Hello,

  We have a credit card interface written in PHP and our cc processor written in Java. What I want is to read the data from the PHP interface, pass it onto the Java processor and then readthe result back.

  The first solution I thought of is to use HTTP. Convert the java application into a Servlet and have the PHP redirect the flow to the Servlet. This is a possible solution but I am wondering how I could read the result back from the servlet (mind you I haven't got a clue about PHP syntax in order to read the input stream).

  The second solution is to use the Java extensions that come with PHP4. The problem here is that the live server is not configured with the Java extensions and I do not know how feasible it would be to take it down, recompile PHP with Java support and then run it.

  Also I am not sure how stable this Java extension is.

  Also, I found out that in order to do redirection to another page I have to use the header("Location: URL"); code. Does anyone knwo how I can pass variables along with it as well? Something similar to the following in Java

<jsp:forward page="myPage.jsp" >
   <jsp:param name="param1"
      value="value1" />
</jsp:forward>

  Any more thoughts on the above two solutions? 500 points and an A answer for good opinions/information.
0
girionis
Asked:
girionis
  • 4
  • 2
  • 2
  • +1
1 Solution
 
lozlozCommented:
hi,

you can use header("Location: page.jsp?variable1=value1&variable2=value2"); but i suppose you'd want it to be a bit more secure. if you wanted to use the post method then you could use this function: http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51. this could be used to essentially forward the form's values directly to java so it would be like posting the form to a java page after you've performed your php functions on the data. regarding java extensions, from the manual:

Warning
This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.
 
having said that it might be feasible to take down php, add the option to include the extension and restart it. that's all i can think of for now

loz
0
 
aolXFTCommented:
The java extension is experimental. You could however add java functionality to PHP, using the Extension Mechanism.

That means you compile the java extension as an external module, and add it in using the extensions area of the php.ini file.

If you are using the apache module, on Linux, taking the server down and putting it back up with Java Support(after you've compiled the extension, and added it to php.ini), is simply a case of running 'apachectl restart'.
0
 
aolXFTCommented:
Sorry, didn't read the question properly, You couldn't get the java extension installed. TBH, if you can't get the extension installed, you aren't very likely to get PHP installed with the java extension either.

One method you could use would be to store the information locally(either in files, or a database), that you put them into through PHP, and take them out through Java/JDBC.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
girionisAuthor Commented:
 Thank you both for your replies.

  aolXFT:

> You couldn't get the java extension installed.

  Why I couldn't get the java extension installed? I haven't tried it yet, I am just asking for opinions :)

  As for the DB/local file suggestion, I do not think it's a right idea. I am not familiar with PHP and its syntax in general. Also I will need to notify PHP somehow for the result (i.e. if the cc is accepted or rejected) that's why I thought about the Java extension.

  I will leave this question open for now for any more suggestions :)
0
 
lozlozCommented:
when sending the result of the cc transaction, you can simply use variables in the url query string as i said - phppage.php?jspvariable=ccaccepted. this would be access in php as the variable $_GET["jspvariable"] (e.g. if($_GET["jspvariable"] == "ccaccepted") { print "transaction successful!"; } else { print "transaction failed."; }

as i said, if you want to keep all the variables integrated within the system rather than exporting them externally then bringing them back in, the function i provided above may be the one to use. using a database/flat file system would be feasible in my opinion as long as you could use a database which was easy to access from both php and java

loz
0
 
girionisAuthor Commented:
 Yes but I need to send the request from PHP to a Servlet/JSP page and not another PHP. The problem is not how to send the request (I can simply redirect the flow) but how I can read the result back from the JSP page? The only thing I can think of is to read the request's input stream.

  For example, lets say that I have a PHP file with the following:

header("Location: page.jsp?variable1=hello");

  Then when I run the above and the flow is redirected to the page.jsp in the page.jsp I have smth like:

<%
os = response.getOutputStream();
if (request.getParameter(variable1).equals("hello"))
{
   os.println("hello to you too");
}
else
{
    os.println("another hello");
}
%>

  Now how should I read the string "hello to you too" that comes from the JSP page for example? Once the request is forwarded is there any way I can get back to it?
0
 
arjendvCommented:
You should use the curl library, it anables you to post data to your jsp script, and get the results back in php.
There are a lot of examples in the user comments on http://nl.php.net/manual/nl/ref.curl.php  .
Using curl, you will also be able to post data via https to make it more secure.
Im sorry that i dont have the time to post a whole solution, but im sure this will point you in the right direction.
Using redirects will never be secure,and may cause potetial problems if users press the back and forward buttons in their  browser.

Arjen

0
 
girionisAuthor Commented:
 Thank you for your answers. I am currently evaluating all of the suggestions, mainly the Java extension and the curl option. I will get back to you when I have some more info :)

  Meanwhile any more suggestions/info/ideas are more than welcome.
0
 
girionisAuthor Commented:
 Thank you, I finally used cURL and I found it easier to install and also use.

  Also thanks to the other two guys/gals who have helped me. I will post two separate questions for you so you can also get some points for your help and suggestions :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now