Jump to content

Get headers from ob_get_contents


Dareros

Recommended Posts

Hi;

I want to get the response headers using ob_get_contents ?

 

For example using file_get_contents, it is easy by accessing the variable $http_response_header like that :

<?php
$content = file_get_contents($url);
print_r($http_response_header);
?>

But how to do that using ob_get_contents without a file_get_contents ? something like for example :

<?php
ob_start();
include($path_to_script_here);
$string = ob_get_contents();
// Access the headers here
ob_end_clean();
?>

Thank you

Edited by Dareros
Link to comment
Share on other sites

Hi, but how to get the status code and other headers information ?

This is the header i get, still doesn't contain all the info why ?

0 : X-Content-Type-Options: nosniff
1 : Server: Apache
2 : X-Powered-By:
3 : P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
4 : Content-Type: text/html; charset=utf-8
5 : Expires: Mon, 1 Jan 2001 00:00:00 GMT
6 : Last-Modified: Wed, 08 Oct 2014 15:09:06 GMT
7 : Cache-Control: post-check=0, pre-check=0
8 : Pragma: no-cache

Thank you

Edited by Dareros
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.