-3

i'm newbie in cURL and ajax. but i triying to learn by myself but i can't find how to change cURL CMD script to cURL PHP script

and here my cuRL CMD script :

    curl 'https://example.url' ^
  -H 'authority: example.url' ^
  -H 'accept: application/json, text/javascript, */*; q=0.01' ^
  -H 'x-requested-with: XMLHttpRequest' ^
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' ^
  -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' ^
  -H 'origin: https://example.url' ^
  -H 'sec-fetch-site: same-origin' ^
  -H 'sec-fetch-mode: cors' ^
  -H 'sec-fetch-dest: empty' ^
  -H 'referer: https://example.url/cabinet' ^
  -H 'accept-language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7,ru;q=0.6' ^
  -H 'cookie: __cfduid=df9e3e9a3bb86a17fac6a77460986bf331607125445; first_visit=2020-12-04+23%3A44%3A05; _ga=GA1.2.1715088206.1607125455; _ym_uid=1607125462299065960; _ym_d=1607125462; __tawkuuid=e::mastercoin.top::Uyuj2F4DyhakerP96QtLiS1jwh7Fa09FBv4BaZIKse+e9SkL9OymuLfdeqM9OIRY::2; _gid=GA1.2.461796546.1607308932; _ym_isad=2; _ym_visorc=w; __atuvc=13%7C49%2C7%7C50; __atuvs=5fcd9680d793a519006; TawkConnectionTime=0' ^
  --data-raw 'chain=BTC' ^
  --compressed

it would be good if anyone help me.

1 Answers1

1

The following PHP code will achieve the same result according to your cURL command:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://example.url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

$headers = array();
$headers[] = 'Authority: example.url';
$headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
$headers[] = 'X-Requested-With: XMLHttpRequest';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36';
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
$headers[] = 'Origin: https://example.url';
$headers[] = 'Sec-Fetch-Site: same-origin';
$headers[] = 'Sec-Fetch-Mode: cors';
$headers[] = 'Sec-Fetch-Dest: empty';
$headers[] = 'Referer: https://example.url/cabinet';
$headers[] = 'Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7,ru;q=0.6';
$headers[] = 'Cookie: __cfduid=df9e3e9a3bb86a17fac6a77460986bf331607125445; first_visit=2020-12-04+23%3A44%3A05; _ga=GA1.2.1715088206.1607125455; _ym_uid=1607125462299065960; _ym_d=1607125462; __tawkuuid=e::mastercoin.top::Uyuj2F4DyhakerP96QtLiS1jwh7Fa09FBv4BaZIKse+e9SkL9OymuLfdeqM9OIRY::2; _gid=GA1.2.461796546.1607308932; _ym_isad=2; _ym_visorc=w; __atuvc=13%7C49%2C7%7C50; __atuvs=5fcd9680d793a519006; TawkConnectionTime=0';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);