Jump to content
xisto Community
Sign in to follow this  
khalilov

Php To Java

Recommended Posts

You are going to have a problem with this, obviously, given that PHP and JAVA are running on two different computers. Remeber that PHP is running on the web server and by the time a web page starts loading on the local client (or web site visitor) machine PHP is already done and no longer executing. Then once the page is loaded for the visitor any Java script or Java applet can run. Thus the best method for the two to share data seems to be the web page and/or the HTML created by PHP. Perhaps trying to have a form element (hidden if you wish) with a value written in by the PHP and then once the Java starts to execute have Java read that value into a variable. There may be other ways as well but this is off the top my head and sems to be a fairly simple solution.

Share this post


Link to post
Share on other sites

Do "View | Page Source" in your browser, and see what actually arrived in the web page. If $variable had the value 5 in the database accessed by the PHP script, the page source should have var x=5 when it arrives in your browser.

 

If it does not, then you can localize the cause. For example, if the <?php string is still there, you aren't executing the PHP. If the 5 is there but the browser-side result isn't what you want, then you may be generating a web page with a syntax error, such as a missing semicolon.

 

If necessary, add some print statements in the PHP that generate plain HTML, so you can debug what is actually happening, as opposed to what you intended.

 

Computers have the bad habit of doing what you tell them to do, not what you want them to do! :mellow:

Share this post


Link to post
Share on other sites

Hmm.. i figured out part of the problem

<html><body><script type="text/javascript"><?php$string="5";echo "var my_var ='".$string."'"; // I should have added the "'" for some reason?>document.write(my_var)</script></body></html>

However when i put this:
<html><body><script type="text/javascript"><?php $x=5;echo "var x='".$x."'";$string="5";echo "var my_var ='".$string."'";?>document.write(x)document.write(my_var)</script></body></html>
It seems when i start operating with two variables, nothing shows.
Page source
<html><body><script type="text/javascript">var x='5'<br>var my_var ='5'document.write(x)document.write(my_var)</script></body></html>
I only need to pass one variable atm, but in the future i might need to pass out more, anyone can tell me why having more than one variable causes issues?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.