I've been getting this problem for a little while now.
The thing is that i have an HTML form proceed by PHP which looks like that:
<?php
if (isset($_POST)) {
$link = mysqli_connect("localhost", "root", "password", "tablename");
$url = $_POST['url'];
$shorturl = str_replace(['/', 'https:', 'http:'], '', $url);
$iconpath = shell_exec("python3 /home/favicon.py {$url}");
$sql = "INSERT INTO links (url, shorturl, iconpath) values ('{$url}', '{$shorturl}', '{$iconpath}')";
$result = mysqli_query($link, $sql);
}
/*
header('Location: /');
exit;
*/
?>
This code is supposed to extract the given URL from the form, execute python file that downloads favicon of the site and insert the data into a MySQL table.
Python code:
import sys
import requests
url = sys.argv[1]
img_data = requests.get(f'{url}/favicon.ico').content
iconpath = '/home/favicon.png'
with open(iconpath, 'wb') as handler:
handler.write(img_data)
print(iconpath)
It all works fine except for the favicon part. When i run the python file from shell, it works fine. When i run it from PHP interactive console by the exact same code written in the form handler, it works fine. But it just won't run properly in the handler, because even when i try to debug it like
echo $iconpath;
it doesn't actually show anything in there. What can i do with it?
P.S. the code actually inserts $url and $shorturl variables into the database, so i said it all works fine except the shell_exec part
python3A more accurate duplicate target is possibly this one, but I'm out of close votes: stackoverflow.com/questions/5456961/…