Jump to content

How to run php from html?


cps13

Recommended Posts

I have the following php code:

 

<?php
exec('java -jar d:\java\Test.jar');
?>

 

Is there a way to execute that jar without leaving the webpage?

 

I'm trying to have an image you click on the executes a jar on the server, so I tried that.

 

When I do action, it goes to the webpage localhost/Test.php, I want it to stay at local host, but still execute the jar.

 

I tried jquery like this:

 

<html>
<head>
<script src="http://code.jquery.com/jquery-lates…
</head>
<body>
<img src="Test.png">
<script>
$("img"").click(functions () {
$.get("Test.php");
});
});
</script>
</body>
</html>

 

But it doesn't click me an option to click.

 

Some help?

 

 

Link to comment
Share on other sites

I realized there is a few errors.

 

I changed them and here is my full code:

 

<html>
<head>
<script src="jquery.js"></script>
</head>
<body>
<div id="a">
<img src="test.png" />
</div>
<script>
$('#a').click(function() {
$.get("test.php");
});
</script>
</body>
</html>

 

That is the full html.

 

The full php is:

<?php
exec('java -jar d:\java\Mainonoff.jar');
?>

 

The full .java file is:

import parport.ParallelPort;

class Mainonoff {

public static void main ( string []args )
{
int rByte = 0;
int bByte=0;
int relay5 = 0x0010;
ParallelPort lpt1 = new ParallelPort(0x378);
rByte = lpt1.readOneByte(0x378);
if ((rByte & relay5) == 16)
lpt1.write(rByte-16);
}
else {
lpt1.write(rByte+16);
}
}
}

 

I don't see why the php/java code matter as if i go to command prompt and do php d:\java\test.php, It does exactly what I want it to do.

 

 

 

My goal with this is to run the jar on the server by clicking an image on the webpage and not leaving the webpage.

 

This is 100% the full code.

Link to comment
Share on other sites

If I can run the php fine from cmd why would it matter?

 

Sorry, I've never really done this before,

 

and my issue is either 1. clicking the image does nothing or 2. if it does work I get no permission to view <?php exec('java -jar d:\java\Mainonoff.jar');?>

Link to comment
Share on other sites

If I can run the php fine from cmd why would it matter?

 

Sorry, I've never really done this before,

 

and my issue is either 1. clicking the image does nothing or 2. if it does work I get no permission to view <?php exec('java -jar d:\java\Mainonoff.jar');?>

 

Yes, it matters, because what works from the command line doesn't necessarily work from the browser, as depending on how things have been setup, the environment  of the two -- CLI (php.exe) and php as an apache module are different.  As an apache module php runs as the apache configured user, often with an environement that has a minimal or empty path environment variable associated with it. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.