Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

323
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda