1

I am trying to run a shell command from php to update a dns ip address but it doesn't work and I don't see why it's not working.

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

when I type directly in the console

curl -L https://dynupdate.no-ip.com/[email protected]&password=sfddeaeZZ.&hostname=example.sytes.net&ip=$ip&#8221"

it works but with php it doesn't.

5
  • 1
    why not use php curl function? Commented Mar 21, 2017 at 17:35
  • i have tried but maybe something was not right. Commented Mar 21, 2017 at 17:37
  • Make sure PHP has CURL installed. It's a lot easier than trying to use the CLI Commented Mar 21, 2017 at 17:39
  • i think that the script does run, but you dont see the output because you are not forwarding it into the right place. do this echo exec("$command",$output,$return_code); echo $output; echo $return_code; Commented Mar 21, 2017 at 17:40
  • [5] Done ip=$ip -here is something wrong, it doesn't take the IP that is provided Commented Mar 21, 2017 at 17:43

1 Answer 1

1

Use the following code to execute CURL using php's built in functions:

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

as @Machavity commented make sure curl is installed and enabled.

Sign up to request clarification or add additional context in comments.

3 Comments

it's not working for me, maybe has to do with this in the url ? &ip=$ip because $ip = $_POST['ipAddress'];
If you think that is the case simply try with $ip=xxx.xxx.xxx.xxx . Replace the xxx's with your ip address and check
aah sorry it works, I just forgot something from the url, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.