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.

Jafar Pinjar
  • 168
  • 12

0 Answers0