0

I tried to make request using Curl in PHP:
but sometimes the response is:
enter image description here
or

Error:SSL certificate problem: unable to get local issuer certificate

This is the code:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://www.instagram.com/majhcc/?__a=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

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

$headers = array();
$headers[] = 'Authority: www.instagram.com';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Sec-Ch-Ua: \"Microsoft Edge\";v=\"93\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"93\"';
$headers[] = 'Sec-Ch-Ua-Mobile: ?1';
$headers[] = 'Sec-Ch-Ua-Platform: \"Android\"';
$headers[] = 'Dnt: 1';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Mobile Safari/537.36 Edg/93.0.961.52';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headers[] = 'Sec-Fetch-Site: none';
$headers[] = 'Sec-Fetch-Mode: navigate';
$headers[] = 'Sec-Fetch-User: ?1';
$headers[] = 'Sec-Fetch-Dest: document';
$headers[] = 'Accept-Language: en-US,en;q=0.9,ar;q=0.8,mt;q=0.7';
$headers[] = 'Sec-Gpc: 1';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

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

in python it is easy

url = 'https://www.instagram.com/majhcc/?__a=1'
import requests
res = requests.get(url)

can someone help me to solve this problem I am new at programming in PHP at all.

Mohammed
  • 127
  • 3
  • 9

1 Answers1

0

Does this work for you?

$data = json_decode(file_get_contents("https://www.instagram.com/majhcc/?__a=1"));
print_r($data);

enter image description here

outlaw
  • 197
  • 8