我有一个bash脚本,如下所示:
#!/bin/bash
for i in `cat domains` ; do
tag=$(echo -n $i" - "; whois $i | grep -o "Expir.*")
reg=$(echo -n -" "; whois $i | grep "Registrar:")
echo $tag $reg
sleep .5s
done;我希望有一个php页面,用户可以在其中粘贴一个域名列表,当他们点击发送时,它调用bash脚本,处理域名并返回输出。这个是可能的吗?
发布于 2012-08-24 21:26:18
这是可能的,但在使用用户输入执行命令时需要小心。您可以使用exec()或反引号在服务器上从PHP执行命令。
只需确保用户输入的内容实际上是一个URL,而不是要在您的服务器上执行恶意命令的内容。
示例:
您的代码可能如下所示:
$output = array();
$urls = $_POST["urls"];
// perform necessary sanitation checks if needed
exec('/path/to/your/script '. implode(' ', $urls), $output);
echo $output;发布于 2012-08-24 21:28:10
是的,您可以使用exec()或shell_exec()命令
发布于 2012-08-24 21:46:16
您真的需要运行bash脚本吗?下面是等效的PHP代码:
foreach ($domains as $domain) {
$domain = addslashes($domain);
exec("whois '$domain'", $results);
foreach ($results as $line) {
if (preg_match('/Expir.*/', $line, $matches)) $tag = $matches[0];
if (preg_match('/Registrar:/', $line)) $reg = $line;
}
echo $domain.' - '.$tag.' - '$reg."\n";
usleep(500000);
}https://stackoverflow.com/questions/12110225
复制相似问题