Forum Moderators: coopster
I have a requirement of displaying HTTP Response headers in the same page being redered using PHP.
This is to track various responses sent by the Apache Server for same page on different scenarios (like 200, 304, 503)
I have a single php file as follows:
-------index.php------------------------------------------------------------------
<?php
header('Cache-Control: no-cache');
print('<?xml version="1.0" encoding="ISO-8859-1"?>'."\n");
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title>
<link type="text/css" rel="stylesheet" href="mycss.css"/>
</head>
<body>
<p>This page contains the header 'Cache-Control: no-cache'<br/>
<?php echo date("F j, Y, g:i:s a"); ?><br/>
</body>
</html>
-----end of index.php--------------------------------------------------------------------
This page has a header "Cache-Control". If this page is retrieved from the local Cache then 304 may be received. If Origin server sends then may be 200, if Origin server is unable to render then may be 503 received. Whereas it is required to capture these response headers in the same page and display.
What code can be added to include the Status code and Status text to get displayed. I have Apache/v1.3.27 on Linux with PHP 4.4.8
-Santosh
At my end, I do not have control over upgrading Apache or PHP. The server is in public domain and our clients are using round the clock. I am forced to do with existing versions. Possibly I may have to wait for some more R&D/suggestions. However please keep posting your invaluable suggestions.
Santosh
<pre>
<?php
header('Cache-Control: no-cache');
print 'Apache Headers List (headers going to be sent): ';
print_r(headers_list()) . "\n";
print 'Apache Response Headers: ';
print_r(apache_response_headers()) . "\n";
?>
</pre>
// Prints:
Apache Headers List (headers going to be sent): Array
(
[0] => X-Powered-By: PHP/5.2.8
[1] => Cache-Control: no-cache
)
Apache Response Headers: Array
(
[X-Powered-By] => PHP/5.2.8
[Cache-Control] => no-cache
)