Jump to content

How to read cURL response header?


sldhana

Recommended Posts

I am trying to read a particular response header posted by cURL and I am not too sure on how to go about doing this,.

 

This is a sample header I get:

HTTP/1.1 200 OK

Date: Sat, 27 Dec 2008 04:15:59 GMT

Server: Microsoft-IIS/6.0

Set-Cookie: JSESSIONID=21EDA47891D6A4B337AB8E1EB136306E; Path=/StgWeb; Secure

Cache-Control: no-cache

Pragma: no-cache

Expires: 0

Payment-Verified: TRUE

Content-Type: text/html

Content-Length: 0

 

What I need is to read the Payment Verified line.

 

Is there an easy way to do this?  Or I have to break the response by it's new lines?

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/138532-how-to-read-curl-response-header/
Share on other sites

<?php
$header = <<<HEADER
HTTP/1.1 200 OK
Date: Sat, 27 Dec 2008 04:15:59 GMT
Server: Microsoft-IIS/6.0
Set-Cookie: JSESSIONID=21EDA47891D6A4B337AB8E1EB136306E; Path=/StgWeb; Secure
Cache-Control: no-cache
Pragma: no-cache
Expires: 0
Payment-Verified: FALSE
Content-Type: text/html
Content-Length: 0
HEADER;

$hArray = explode("\n",$header);
echo (in_array('Payment-Verified: TRUE',$hArray)) ? 'Payment was verified' : '';
echo (in_array('Payment-Verified: FALSE', $hArray)) ? 'Payment was not verified' : '';

?>

 

Since I know nothing about regex, here would be my solution. I am assuming that a non-verified payment would simply return false.

 

Nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.