0

I am using curl as like below. http://99.88.77.121/sample/curl.php

$ch = curl_init();
        $ip = "Some IP address";
        curl_setopt($ch, CURLOPT_URL, 'http://99.88.77.121/test/index.php');
        curl_setopt($ch, CURLOPT_POST, 1);

        $payload = json_encode(
                            array( 
                                'username' => 'abc', 
                                'password' => '1234'
                                )
                            );

        curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec ($ch);

The above code sends the data to the Url.

I have code like below in my http://99.88.77.121/test/index.php

<?php 

  $fp = fopen('php://input', 'r');
  $rawData = stream_get_contents($fp);
  $data = json_decode($rawData);
  $username = $data->username;
  $password = $data->password;
  $projectName = "testFolder";
  chdir('../');
  //chdir($projectName);
  $command = "sudo chmod -R 777 ".$projectName;
  shell_exec($command);

?>

I am trying give full permission for testFolder using above code,

is chdir() and shel_exec() will work here? In my case its not working

If i run the index.php in browser, its working fine. but not from the curl call.

Can anyone look into it and update me your thoughts please.

7
  • why don't you use chmod function? Commented May 29, 2019 at 12:51
  • Not answerable without guessing the error message. Look into the linked references to investigate. Commented May 29, 2019 at 12:55
  • @mario, what need to guess, did you understand my question? my question is completely different Commented May 29, 2019 at 12:56
  • Yes, I think I did. No trace of error_reporting/debugging in your sample code though. Commented May 29, 2019 at 12:57
  • @mario, what info you need? have you got my question,? please read clearly then mark it as duplicate Commented May 29, 2019 at 12:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.