Rather a simple question still puzzling me:(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
efrog
Forum Newbie
Posts: 2
Joined: Tue Nov 28, 2006 1:52 pm

Rather a simple question still puzzling me:(

Post 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.
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

To me it appears that you're trying to perform a http request and get the http headers back...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

efrog
Forum Newbie
Posts: 2
Joined: Tue Nov 28, 2006 1:52 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

But there are replacements for php4 discussed in the user contributed notes.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

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