-4

I want to convert command line cURL to PHP cURL in order to have better control.

Note it is included authentication with MYUSER and MYTOKEN.

Linux server is running Apache 2 and PHP 7.2.

curl -u 'MYUSER:MYTOKEN' 'https://example.com' -X POST --data '{"domainNames":["example.org","site2.com"]}'

What PHP code would you use to obtain the same functionality?

1
  • (Of course, one could find better duplicates with a bit more search effort.) Commented Jan 21, 2019 at 18:17

1 Answer 1

0

I haven't used PHP cURL, but I have done stuff using PHP exec. WARNING this is not completely recommended. But here is what I think you can be able to do:

<?php
   echo exec('curl -u \'MYUSER:MYTOKEN\' \'https://example.com\' -X POST --data \'{"domainNames":["example.org","site2.com"]}\'');
?>

More advanced examples can be found here: http://php.net/manual/en/function.exec.php

Along with this which is what you might actually be looking for: http://php.net/manual/en/book.curl.php

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

3 Comments

(If you use double quotes for the encapsulation you don't need to escape the single quotes)
@user3783243 I tried that but {"domainNames":["example.org","site2.com"]} has double quotes then I would have to escape that right?
Yes, or looks like that is JSON so maybe, put it into an array and do json_encode.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.