Solved

PHP to Java

Posted on 2003-11-19
9
364 Views
Last Modified: 2006-11-17
 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
Comment
Question by:girionis
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
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
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
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
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
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
 
LVL 35

Author Comment

by:girionis
Comment Utility
 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 13

Expert Comment

by:lozloz
Comment Utility
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
 
LVL 35

Author Comment

by:girionis
Comment Utility
 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
 
LVL 1

Accepted Solution

by:
arjendv earned 500 total points
Comment Utility
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
 
LVL 35

Author Comment

by:girionis
Comment Utility
 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
 
LVL 35

Author Comment

by:girionis
Comment Utility
 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now