Thank you.
Here is the cURL ftp code I have tried to use most recently, together with the response I am getting.
$str contains ascii text (a php script).
I have no problems at all accessing
ftp://hostingdomain/auth/
and the files within it, on a read or write basis, with an FTP client
(in the case OSX Fetch) in either passive or active mode.
In essence, I am trying to create (write) test.php within
ftp://hostingdomain/auth/
, and overwrite it if it is already there. The tmp file is being correctly created,
and deleted once the script exits.
$ch = curl_init();
$tmp = tmpfile();
fwrite($tmp, $str);
fseek($tmp, 0);
curl_setopt($ch, CURLOPT_URL, 'ftp://hostingdomain/auth/test.php');
curl_setopt($ch, CURLOPT_USERPWD, "myftpusername:myftppassword");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $tmp);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($str));
curl_exec ($ch);
$error_no = curl_errno($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close ($ch);
fclose($tmp);
if ($error_no == 0) {
$message = 'File uploaded successfully.';
} else {
$message = '<BR>File upload error: '.$error_no.' '.$error.'<BR>';
print_r ($info);
}
echo $message;
--------Response - Script is being run on "sending" server.
Array (
[url] => ftp://hostingdomain/auth/test.php
[content_type] =>
[http_code] => 227
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 16.64937
[namelookup_time] => 0.200538
[connect_time] => 0.288836
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0
)
File upload error: 7
couldn't connect to host
Essentially I am getting a timeout and then the above $info and $message
comes back. Doing exactly the same transfer into
ftp://hostingdomain/auth/test.php with my FTP client works just fine.
Related
I have a cURL command using which I get authenticated to a website and it gives a cookie in response, then subsequently using this cookie I can make REST API calls to this service
Here is the working cURL command:
curl -v -l -H "Content-Type: application/x-www-form-urlencoded" -H "Referrer:https://mywebsiteurl.com?ticket=unique_ticket_id" -d "_charset_=UTF-8&errorMessage=User+name+and+password+do+not+match&resource=%2F&username=username%40domain.com&password=XXXXXX&nextpage=welcomeCM.jsp&viewInfo=&ticket=unique_ticket_id" -X POST https://mywebsiteurl.com/index.jsp
In the above command ticket parameter contains a unique ticket id that is passed along with the website url
Now, I'm trying to accomplish the same using cURL PHP, here is the PHP code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://mywebsiteurl.com/index.jsp");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "_charset_=UTF-8&errorMessage=User+name+and+password+do+not+match&resource=%2F&username=username%40domain.com&password=XXXXXX&nextpage=welcomeCM.jsp&viewInfo=&ticket=unique_ticket_id");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'Referrer: https://mywebsiteurl.com?ticket=unique_ticket_id'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
echo $result;
curl_close ($ch);
Here echo $result shows nothing
I then tried var_dump($result); and it gives this output: string(0) "" which means nothing is getting returned in $response
After this I tried curl_getinfo and added the following code:
echo "<pre>";
$info = curl_getinfo($ch);
print_r($info);
echo "</pre>";
And this gave me the following array:
Array
(
[url] => https://mywebsiteurl.com/index.jsp
[content_type] => text/html;charset=UTF-8
[http_code] => 302
[header_size] => 1306
[request_size] => 619
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.540687
[namelookup_time] => 0.028262
[connect_time] => 0.171774
[pretransfer_time] => 0.462507
[size_upload] => 280
[size_download] => 0
[speed_download] => 0
[speed_upload] => 181
[download_content_length] => 0
[upload_content_length] => 280
[starttransfer_time] => 1.54066
[redirect_time] => 0
[redirect_url] => https://mywebsiteurl.com/welcomeCM.jsp?username=username#domain.com&locale=en_US
[primary_ip] => YY.YYY.YYY.YY
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => XX.XX.XXX.XX
[local_port] => 47692
)
Now my goal is to get the cookie in $result, but it is empty & nothing is getting returned into it
Is it that something is missing in the cURL command equivalent PHP code?
Can someone please help me out & point me in the direction to retrieve the cookie
Thanks a lot!
UPDATE
I added curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); to the request to have it follow the 302 redirect after successful login
But this time after the execution of cURL, echo $result is redirecting my current local webpage to /Dashboard?viewInfo= which obviously does not exist
Also this time var_dump($result); is resulting in: string(1462) " "
And curl_getinfo($ch) this time is giving the following array:
Array
(
[url] => https://mywebsiteurl.com/welcomeCM.jsp?username=username#domain.com&locale=en_US
[content_type] => text/html;charset=UTF-8
[http_code] => 200
[header_size] => 1821
[request_size] => 956
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 1.746911
[namelookup_time] => 1.5E-5
[connect_time] => 1.5E-5
[pretransfer_time] => 6.2E-5
[size_upload] => 0
[size_download] => 1462
[speed_download] => 836
[speed_upload] => 0
[download_content_length] => 1462
[upload_content_length] => 0
[starttransfer_time] => 0.146587
[redirect_time] => 1.6003
[redirect_url] =>
[primary_ip] => YY.YYY.YYY.YY
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => YY.YY.YYY.YY
[local_port] => 47705
)
Still can't get the required cookie here,
Please help!
If you want to use curls given functionality you can try using CURLOPT_COOKIEJAR / CURLOPT_COOKIEFILE, to store and get your cookie. This if file based.
In this case, curl will then write any Cookie related Information in a file.
You can define where this file will be located.
By using CURLOPT_COOKIEJAR , you will tell curl that it shall capture the cookie data.
// create cookie file
$cookie = __DIR__ . "/where/you/want/to/store/your/cookie/mycookie.txt";
fopen($cookie, "w");
// you may want to use some random identicator in your cookie file
// to make sure it does not get overwritten by some action
// prepare login
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://mywebsiteurl.com/index.jsp");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// tell curl to follow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURlOPT_POSTFIELDS, "username=usernam&password=XXXXXX");
curl_setopt($ch, CURLOPT_POST, 1);
// set a jar, to store your cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'Referrer: https://mywebsiteurl.com?ticket=unique_ticket_id'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// do login
$loginResult = curl_exec($ch);
// check if your login has worked according to the given result by any method you want
if (preg_match("/Welcome/", $loginResult)) {
// simple regex for demonstration purpose
}
// now you could load your cookie out of the file, or just use the file for future requests
If your login has worked, you will have all information stored in your cookie file.
Now you can use that cookie again with the curlopt CURLOPT_COOKIEFILE for future requests.
// do other request, with your cookie
curl_setopt($ch, CURLOPT_URL, "https://mywebsiteurl.com/api/rest.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "your new post data");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// set a jar to update your cookie if needed
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
// give curl the location of your cookie file, so it can send it
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
I'm trying to setup the following code to accept curl requests from php with nodejs via https protocol. I know the code works with http in nodejs side but as soon as I switch the protocol to https, "RECEIVED" is not logged in nodejs. This is:
app.post('/posts', function(req, res){
console.log("RECEIVED");
});
Suming up:
"received" is logged with nodejs in http mode
"received" is NOT logged with nodejs in https mode
$curl_url (in HTTP) 'http://127.0.0.1:'.$socket_port.'/posts';
$curl_url (in HTTPS) 'https://127.0.0.1:'.$socket_port.'/posts';
Does anybody have any idea on this? Here is my curl function:
$ch = curl_init();
$ch_options = array("Expect:");
if($encode_json){
array_push($ch_options,"Content-type: application/json");
$data = json_encode($data);
}else{
$data = http_build_query($data);
}
//$data isn't received in either format mode
curl_setopt($ch, CURLOPT_HTTPHEADER, $ch_options);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
$feedback = curl_getinfo($ch);
curl_close($ch);
EDIT: the code that decides it all (called after app.post, which works with http. With https only this functionality [app.post('/post'...] fails AFAIK)
if(protocol == "https"){
preparedApp = require(protocol).createServer(sslOptions,app);
}else if(protocol == "http")
preparedApp = require(protocol).Server(app);
preparedApp.listen(socket_port, function(){
//literally nothing here
});
$feedbackdump:
print_r:
Array
(
[url] => https://127.0.0.1:socket_port/posts
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 1
[redirect_count] => 0
[total_time] => 0.005724
[namelookup_time] => 1.1E-5
[connect_time] => 5.5E-5 //IT IS connecting / knows presence, but doens't route /posts...
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 127.0.0.1
[certinfo] => Array
(
)
[primary_port] => socket_port
[local_ip] => 127.0.0.1
[local_port] => 54576
)
After doing some research I noticed curl_exec($ch) was returning false. After programming a throw such as
try{ $test = curl_exec($ch)
if ($test)
throw new Exception(curl_error($ch), curl_errno($ch));
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
I got the error Curl failed with error #51: SSL: certificate subject name 'mydomain.com' does not match target host name '127.0.0.1'
TL;DR: So I just added
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
to the ch options and it is now working
I'm trying to run an URL (which have signout functionality) through the CURL. But it is returning 302 http code. Same url when i run through the POSTMAN ( Google Chrome addon ) or POSTER ( Firefox Addon) , then it is return proper result ( {"status" : "success" } ). Any help would be greatly appreciated.
URL (JAVA APPLICATION URL) : http://website.mywebsite.com:8083/VideoBook/signout.action
MY CODE :
// Open log file
$logfh = fopen("GeoserverPHP.log", 'w') or die("can't open log file");
// Initiate cURL session
$service = "http://website.mywebsite.com:8083/VideoBook/";
$request = "signout.action";
$url = $service . $request;
$ch = curl_init($url);
// Optional settings for debugging
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $logfh);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_REFERER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, true);
//Required GET request settings
// $passwordStr = "geosolutions:Geos";
// curl_setopt($ch, CURLOPT_USERPWD, $passwordStr);
//GET data
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
//GET return code
$successCode = 200;
$buffer = curl_exec($ch);
echo "CURL INFO : <BR/> " ;
print_r(curl_getinfo($ch));
echo "CURL OUTPUT : <BR/> " ;
print_r($buffer);
// Check for errors and process results
$info = curl_getinfo($ch);
if ($info['http_code'] != $successCode) {
$msgStr = "# Unsuccessful cURL request to ";
$msgStr .= $url." [". $info['http_code']. "]\n";
fwrite($logfh, $msgStr);
} else {
$msgStr = "# Successful cURL request to ".$url."\n";
fwrite($logfh, $msgStr);
}
fwrite($logfh, $buffer."\n");
curl_close($ch);
fclose($logfh);
OUTPUT IN BROWSER :
CURL INFO :
Array
(
[url] => http://website.mywebsite.com:8083/VideoBook/signout.action
[content_type] =>
[http_code] => 302
[header_size] => 254
[request_size] => 105
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.58976
[namelookup_time] => 0.004162
[connect_time] => 0.297276
[pretransfer_time] => 0.297328
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.589739
[redirect_time] => 0
[redirect_url] => https://hpecp.mywebsite.com:8443/cas/login?service=http%3A%2F%2Fwebsite.mywebsite.com%3A8083%2FVideoBook%2Flogin.action
[primary_ip] => 125.21.227.2
[certinfo] => Array
(
)
[primary_port] => 8083
[local_ip] => 10.0.0.8
[local_port] => 50710
)
CURL OUTPUT :
LOG File Details :
* Hostname was NOT found in DNS cache
* Trying 125.21.227.2...
* Connected to website.mywebsite.com (125.21.227.2) port 8083 (#0)
> GET /VideoBook/signout.action HTTP/1.1
Host: website.mywebsite.com:8083
Accept: application/json
< HTTP/1.1 302 Moved Temporarily
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Location: https://hpecp.mywebsite.com:8443/cas/login?service=http%3A%2F%2Fwebsite.mywebsite.com%3A8083%2FVideoBook%2Flogin.action
< Content-Length: 0
< Date: Tue, 20 May 2014 06:02:29 GMT
<
* Connection #0 to host website.mywebsite.com left intact
* Issue another request to this URL: 'https://hpecp.mywebsite.com:8443/cas/login?service=http%3A%2F%2Fwebsite.mywebsite.com%3A8083%2FVideoBook%2Flogin.action'
* Hostname was NOT found in DNS cache
* Trying 15.126.214.121...
* Connected to hpecp.mywebsite.com (15.126.214.121) port 8443 (#1)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* Unknown SSL protocol error in connection to hpecp.mywebsite.com:8443
* Closing connection 1
# Unsuccessful cURL request to http://website.mywebsite.com:8083/VideoBook/signout.action [302]
try to add ssl verify false and follow location and now all set
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//output:-
CURL INFO :
Array ( [url] => https://exampl.com:8443/cas/login?service=http%3A%2F%2Fexample%3A8083%2FVideoBook%2Flogin.action [content_type] => text/html;charset=UTF-8 [http_code] => 200 [header_size] => 593 [request_size] => 273 [filetime] => -1 [ssl_verify_result] => 18 [redirect_count] => 1 [total_time] => 3.073 [namelookup_time] => 0 [connect_time] => 0.577 [pretransfer_time] => 1.794 [size_upload] => 0 [size_download] => 8003 [speed_download] => 2604 [speed_upload] => 0 [download_content_length] => 8003 [upload_content_length] => -1 [starttransfer_time] => 2.387 [redirect_time] => 0.686 )
You so need to check auth credentials on your end
I think, adding these three parameter CURLOPT_REFERER, CURLOPT_COOKIEJAR, CURLOPT_COOKIEFILE and an valid cookie file can solve this. I didn't tested the code.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Do the job.
In order to log out of any kind of session, you first need to be logged in, so the service must be expecting some reference to an existing session.
Either it expects you to give it information about which user should be logged out, or it is intended to log your script out after a series of calls to other services.
What it cannot do is automatically log out the user who is accessing your page, because it has no way of seeing them. The request originates entirely on your server, and only contains the information you pass to it with CURL. Nor will you be able to give it the information a browser would have, unless your script is on the same domain, as the browser will not pass your script the cookies set by the other site.
enter code herePreviously, the below function to save image from a certain "$url" to "$saveto" was working properly. Somehow, when i try to grab this domain picture, i.e. http://pic.pimg.tw/ellenitn/4a439fc4b1c2e.jpg
It failed to work anymore (it was working 2 days ago and now it stopped working, the images saved is all 0kb)
function grab_image($url,$saveto)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
$var = fwrite($fp, $raw);
fclose($fp);
return $var;
}
Can I know how to go around debugging this? I have tried file_get_contents(), but it failed to work as well, code error -> php_network_getaddresses: getaddrinfo failed: Name or service not known.
Edited:
When I use:
print_r(curl_getinfo($ch));
I got this information:
Array (
[url] => http://pic.pimg.tw/ellenitn/4a439fc4b1c2e.jpg
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => 0
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[certinfo] => Array ( )
[primary_ip] =>
[redirect_url] =>
)
The given URL returns an "unknown host" error.
As from your code, you are not doing any error handling. Suppose the following:
the server name is wrong (as the above url)
the server doesn't respond
the server gives an error (http 50x)
the link is not an image
the link is gone (http 40x)
you need to catch all of the above in order to be sure to actually got at least what you want before starting to save something to a file.
As from your try:
I have tried file_get_contents(), but it failed to work as well, code
error -> php_network_getaddresses: getaddrinfo failed: Name or service
not known.
you are getting the proper error message already. file_get_contents()will give you all needed control to handle such errors.
1: Downloading a file and saving it with file_put_contents()
<?php
$url = 'http://pic.pimg.tw/ellenitn/4a439fc4b1c2e.jpg;
$savepath = '/local/path/to/4a439fc4b1c2e.jpg'; //make sure you have write permissions on "/local/path/to/"
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
file_put_contents($savepath, $data);
?>
2: Use cURL to download straight to a file stream
<?php
$url = 'http://pic.pimg.tw/ellenitn/4a439fc4b1c2e.jpg';
$savepath = '/local/path/to/4a439fc4b1c2e.jpg';
$fp = fopen($savepath, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
I am using Curl in PHP to call an API.
According to their documentation, they are returning "Authentication-Callback" within the returned page's header.
It works perfectly when I paste the URL into the browser, but Curl seems to leave it out.
Here is my code
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.themoviedb.org/3/authentication/token/new?api_key=[MY_API_KEY]&language=en');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$results = curl_exec($ch);
$headers = curl_getinfo($ch);
Here is the returned header
Array
(
[url] => http://api.themoviedb.org/3/authentication/token/new?api_key=[MY_API_KEY]&language=en&
[content_type] => application/json;charset=utf-8
[http_code] => 200
[header_size] => 470
[request_size] => 137
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.109
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.047
[size_upload] => 0
[size_download] => 116
[speed_download] => 1064
[speed_upload] => 0
[download_content_length] => 116
[upload_content_length] => 0
[starttransfer_time] => 0.109
[redirect_time] => 0
[certinfo] => Array
(
)
)
As far as I can tell, everything is right. Curl returns the data that I need perfectly, just not the correct headers.
Any help is appreciated!
What you're doing right now is getting stored information about the header via curl_getinfo() which only gets the information in the OPT list on that page.
What you should do instead is to return the header and then manually separate it:
curl_setopt($ch, CURLOPT_HEADER, 1);
// The rest of your options
$output = curl_exec($ch);
// Since the end of the header is always delimited by two newlines
$output = explode("\n\n", $output, 2);
$header = $output[0];
$content = $output[1];
This is more work but will get you the real headers.
This is my code to do what phsource has suggested the headers are put into the $headers array
# Extract headers from response
preg_match_all('%HTTP/\\d\\.\\d.*?(\\r\\n|\\n){2,}%si', $curl_result, $header_matches);
$headers = preg_split('/\\r\\n/', str_replace("\r\n\r\n",'',array_pop($header_matches[0])));
# Convert headers into an associative array
if(is_array($headers))
{
foreach ($headers as $header)
{
preg_match('#(.*?)\:\s(.*)#', $header, $header_matches);
if(isset($header_matches[1]))
{
$headers[$header_matches[1]] = $header_matches[2];
$headers['lowercase'][strtolower($header_matches[1])] = $header_matches[2];
}
}
}
# Remove the headers from the response body
$curl_result = preg_replace('%HTTP/\\d\\.\\d.*?(\\r\\n|\\n){2,}%si','',$curl_result);
you may want to replace \r\n with PHP_EOL as you see fit