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.