When PHP uses CURL to access a remote URL, the following error occurs: Cannotmodifyheaderinformation...

Source: Internet
Author: User
Curl code: {code...} error: {code...} access the URL directly in the browser. I also searched for the solution to the above problems on the internet. most of them were modifying the PHP file or modifying the PHP configuration... But my idea is to use CURL to access the code with the browser... curl:

$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); // request URL curl_setopt ($ ch, CURLOPT_HEADER, 0 ); // disable the output header information curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE) in file stream format ); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE); if (! Is_null ($ postData) {curl_setopt ($ ch, CURLOPT_POST, 1); // POST submit curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ postData );} $ return = curl_exec ($ ch); curl_close ($ ch); return $ return;

Error:

Cannot modify header information - headers already sent by...

There is no error when accessing the URL directly in the browser.

I also searched for the solution to the above problems on the internet. most of them were modifying the PHP file or modifying the PHP configuration... But my idea is to use CURL to achieve the same effect as browser access? How can this problem be achieved? Because there is no error in browsing the URL.

Reply content:

Curl code:

$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); // request URL curl_setopt ($ ch, CURLOPT_HEADER, 0 ); // disable the output header information curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE) in file stream format ); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE); if (! Is_null ($ postData) {curl_setopt ($ ch, CURLOPT_POST, 1); // POST submit curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ postData );} $ return = curl_exec ($ ch); curl_close ($ ch); return $ return;

Error:

Cannot modify header information - headers already sent by...

There is no error when accessing the URL directly in the browser.

I also searched for the solution to the above problems on the internet. most of them were modifying the PHP file or modifying the PHP configuration... But my idea is to use CURL to achieve the same effect as browser access? How can this problem be achieved? Because there is no error in browsing the URL.

You need a library that encapsulates curl

I checked stackoverflow. it may be that your file code contains the BOM header.
Try to Change encoding to UTF-8 without BOM format.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.