我试图从php运行一个shell命令来更新dns ip地址,但它不起作用,我不明白为什么它不起作用。

$ip =  $_POST['ipAddress'];
$exc =shell_exec("curl -L https://dynupdate.no-ip.com/dns?username=testtt@yahoo.com&password=sfddeaeZZ.&hostname=example.sytes.net&ip=$ip&#8221");

当我直接在控制台中键入时
curl -L https://dynupdate.no-ip.com/dns?username=testtt@yahoo.com&password=sfddeaeZZ.&hostname=example.sytes.net&ip=$ip&#8221"

它可以工作,但对于php则不行。

最佳答案

使用以下代码使用php内置函数执行curl:

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://dynupdate.no-ip.com/dns?username=testtt@yahoo.com&password=sfddeaeZZ.&hostname=example.sytes.net&ip=$ip&#8221");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
?>

正如@machavity所评论的,确保curl已安装并启用。

关于php - PHP执行 curl 无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42934355/

10-14 15:25
查看更多