Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
Curl request works on console but not in PHP

This simple request works on my console

curl 'https://www.nike.com/en'

But in PHP (with or without options like headers, useragent ...) I get Access Denied 403

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.nike.com/en");
$result = curl_exec($ch);

Thanks

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

<?php

class Curl {

    public static function makeRequest($url) {
            $ch = curl_init();
            $request_headers = [
                'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;',
                'Accept-Encoding: gzip, deflate',
                "Connection: keep-alive",
                "Content-Type: text/html; charset=UTF-8",
            ];
            $options = [
                CURLOPT_URL => $url,
                CURLOPT_CONNECTTIMEOUT => 30,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0",
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_AUTOREFERER => true,
                CURLOPT_COOKIESESSION => true,
                CURLOPT_FILETIME => true,
                CURLOPT_FRESH_CONNECT => true,
                CURLOPT_HTTPHEADER => $request_headers,
                CURLOPT_COOKIESESSION => true,
                CURLOPT_ENCODING => "gzip, deflate, scdh",
            ];
            curl_setopt_array($ch, $options);
            $result['content'] = curl_exec($ch);
            $result['header'] = curl_getinfo($ch);
            $result['error'] = curl_error($ch);
            return $result;
    }
}

var_dump(Curl::makeRequest('https://www.nike.com/en')['header']);

Some website strictly check the request headers and return you encoded so .. I added request headers ad decoding method to decode the content

over 4 years ago · Santiago Trujillo Report

0

Well, this would work for you.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.nike.com/en");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40000);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
echo $result;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!