user7972779
user7972779

Reputation:

PHP Curl request response 403 - not authorized

I'm trying to run a PHP curl GET in domain https://www.submarino.com.br. I'm getting 403 (Forbidden). I then tried by the chrome developper to copy the curl request provided in the url and run in bash and get the same answer

My PHP code

public function GetStatusHost(){
    $headers   = Array();
    $headers[] = 'Host:www.submarino.com.br';
    $headers[] = 'Connection:keep-alive';
    $headers[] = 'Cache-Control:max-age=0';
    $headers[] = 'Upgrade-Insecure-Requests: 1';
    $headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
    $headers[] = 'Accept-Language:pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,pt-PT;q=0.5';
    $headers[] = 'Accept-Encoding:gzip, deflate, br';
    $headers[] = "If-None-Match:W/'5beff-TgqN41ZtNiOTyAH2bpA4lvYiKTE'";

    $ch        = curl_init($this->GetKeywordUrl());
    $tmp       = "/home/leilao/public_html/tmp/curl_cookie/cookie.txt";
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36");
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
    //curl_setopt($ch, CURLOPT_COOKIEJAR, $tmp);
    //curl_setopt($ch, CURLOPT_COOKIEFILE,$tmp);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $result = curl_exec($ch);
    $info      = curl_getinfo($ch);
    curl_close($ch); echo $info['http_code']; exit;
    return $info['http_code'];
}

Bash

enter image description here

Any ideas how to fixed this problem?

Response using header SomeHugeOAuthaccess_tokenThatIReceivedAsAString:

enter image description here

Upvotes: 2

Views: 1567

Answers (1)

A.D.
A.D.

Reputation: 2372

Maybe your site (Host:www.submarino.com.br) use an auth credentials to provide the permission for method access. So try to add this lines with a specific credentials:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "username:password"); //Your credentials goes here

or if there a base64string Authorization is used then you can use this also

$header[] = "Authorization: Bearer $access_token";

or

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization', 'OAuth ' . $atoken));

Upvotes: 0

Related Questions