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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.