Simple PHP page to use Python not working

Viewed 25

Thanks for your time. I took a new VPS, just to put online a software I'm developing. The VPS is on CentOs 7. I've installed HTTPD and PHP, Python was already installed. The index page is online. I've found a sample at cyberwarzone and I've created an index.php page like this:

<html>
<body>
<form action="#" method="post">
Name: <input type="text" name="NAME"><br>
<input type="submit" value="NAME">
</form>
</body>
</html>
<?php 
    error_reporting(E_ALL);
    $param1 = $_POST["NAME"];    
    $command = escapeshellcmd("/var/www/html/cyberwarzone.py $param1 ");
    $resultAsString = shell_exec($command);
    echo $resultAsString;
?>

And a cyberwarzone.py file like this:

#!/usr/bin/python
import sys
workvalue = sys.argv[1]
workvalue = workvalue + '\t' + "Hello World, send from Cyberwarzone.py"
print(workvalue)

Now, when I enter any data, nothing happens. Python is in /usr/bin/python and html files are in /var/www/html/. Can anybody help me to troubleshoot it? Thanks.

1 Answers

I've found the problem. I was saving the .py file with windows EOL. Changing them, in NP++, resolved the problem. Thanks for your time

Related