Click here to Skip to main content
15,559,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have shared the code I am using. I want to get the values from user using the HTML code and read it using PHP. Then pass the values from PHP script to python script, do the task and display the output.

For some reason I am unable to do that. Can someone help me?

What I have tried:

<pre lang="HTML"><pre><html>
   <body>
      <head>
         <title>HTML Forms</title>
      </head>
      <p>Add your details:</p>
      <form name="form" method="get">
         Number 1:<br> <input type="number" name="first">
         <br>
         Number 2:<br> <input type="number" name="second">
         <br>
         Number 3:<br> <input type="number" name="third">
         <input type="submit" value="submit" id="submit" />
      </form>
   </body>
</html>


PHP
<pre><?php
$var1 =  $_GET['first'];
$var2 =  $_GET['second'];
$var3 =  $_GET['third'];
$command = escapeshellcmd("python total.py $var1 $var2 $var3");
$output = shell_exec($command);
echo ($output);

?>


Python
import sys

num_1 = sys.argv[1]

num_2 = sys.argv[2]

num_3 = sys.argv[3]

print("total:", num_1+num_2+num_3)
Posted
Comments
Richard Deeming 18-Aug-22 3:45am    
Aside from the fact that you haven't actually described what the problem is, your code is a massive security problem waiting to happen. You accept three values from the querystring, don't validate them in any way, and pass them directly the the shell_exec method.

Do you really want anyone on the internet to be able to execute random shell commands on your server? Because that's the system you're building.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900