Jump to content

How to use curl in prestashop


Recommended Posts

try to use this function:

function get_web_page( $url )
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        CURLOPT_SSL_VERIFYPEER => false     // Disabled SSL Cert checks
    );

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    $header['errno']   = $err;
    $header['errmsg']  = $errmsg;
    $header['content'] = $content;
    return $header;
}

call it with code:

$contents=$this->get_web_page('https://abcd.com/shop/xyz?name=aaaaa&id=1');

  • Like 2
Link to comment
Share on other sites

 

Hi Vekia,

 

Thanks for your reply. Actually your code may gives correct output. But i didnt get the proper output. I think because of some resaons...

 

 If i copy this link and paste to browser, it will goes to the 3rd party server login page and it ask the user name and password. 

when i enter the username and password,the url is executes successfully; So i think we need to pass the username and password through curl.

Edited by franklinfs (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...