Page 1 of 1

Rather a simple question still puzzling me:(

Posted: Tue Nov 28, 2006 1:58 pm
by efrog
Actually I am a newbie of PHP. Now I'm wondering how to get the information showed below:

Code: Select all

Last-Modified: Wed, 14 May 2003 13:06:17 GMT
Expires: Fri, 16 Jun 2003 13:06:17 GMT
As is tried, file_get_contents and file both suck.

Any help would be much appreciated.

Posted: Tue Nov 28, 2006 3:39 pm
by Trenchant
Here's everything you need. All the functions with descriptions of exactly what they do.
http://www.php.net/manual/en/ref.filesystem.php

Posted: Wed Nov 29, 2006 1:28 am
by timvw
To me it appears that you're trying to perform a http request and get the http headers back...

Posted: Wed Nov 29, 2006 1:30 am
by volka

Posted: Wed Nov 29, 2006 2:15 am
by efrog
Web Dummy wrote:Here's everything you need. All the functions with descriptions of exactly what they do.
http://www.php.net/manual/en/ref.filesystem.php
Thanks a bunch. I'll go and see it!

What's more, I'm operation on PHP 443. I am told that get_headers is not available.

Posted: Wed Nov 29, 2006 2:20 am
by volka
But there are replacements for php4 discussed in the user contributed notes.

Posted: Wed Nov 29, 2006 3:57 am
by dibyendrah
Sample file test.php for setting headers using header function.

Code: Select all

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
Sample file read_headers.php for reading headers using get_headers function.

Code: Select all

<?
$headers = get_headers("http://localhost/test.php");
print $headers[5]."\n".$headers[8];
?>
Output :

Code: Select all

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Wed, 29 Nov 2006 15:35:29 GMT
    [2] => Server: Apache/2.2.3 (Unix) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8c PHP/5.1.6 mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 Perl/v5.8.7
    [3] => X-Powered-By: PHP/5.1.6
    [4] => Set-Cookie: PHPSESSID=99912a257264875fee6798d0a08f3c65; path=/
    [5] => Expires: Mon, 26 Jul 1997 05:00:00 GMT
    [6] => Cache-Control: private, no-store, no-cache, must-revalidate
    [7] => Pragma: no-cache
    [8] => Last-Modified: Wed, 29 Nov 2006 15:35:29 GMT
    [9] => Cache-Control: post-check=0, pre-check=0
    [10] => Connection: close
    [11] => Content-Type: text/html; charset=utf-8
)

In this context, you can read only index 5, 8.

Code: Select all

print $headers[5]."\n".$headers[8];
Output :

Code: Select all

Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Wed, 29 Nov 2006 15:37:54 GMT
With Regards,
Dibyendra