php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15693 HTTP HEAD request executes entire script
Submitted: 2002-02-23 18:52 UTC Modified: 2002-02-24 03:57 UTC
From: patrick at ginx dot com Assigned:
Status: Not a bug Package: HTTP related
PHP Version: 4.1.1 OS: FreeBSD 4.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: patrick at ginx dot com
New email:
PHP Version: OS:

 

 [2002-02-23 18:52 UTC] patrick at ginx dot com
Maybe this is the way it's supposed to work, but it doesn't make a whole lot of sense to me.

When processing a HEAD request, mod_php executes the script as if it were a normal GET request. This is unexpected (at least to me) and can lead to unexpected results, such as duplicate execution when dealing with browsers that use a HEAD request prior to a GET request.

For example, test script test.php:
<?php
$fp = fopen("test.out", "a");
fputs($fp, "I'm hit!");
fclose($fp);
?>

and assuming test.out exists and is world-writable.

HEAD /test.php HTTP/1.0

causes the file test.out to be appended to.

This is not what I would expect, but maybe it's unavoidable. A workaround is to look at $_SERVER['REQUEST_METHOD'] and do nothing if it's a HEAD request.


 './configure' '--with-apxs=/usr/local/sbin/apxs' '--with-config-file-path=/usr/local/etc' '--enable-versioning' '--with-system-regex' '--disable-debug' '--enable-track-vars' '--without-gd' '--without-mysql' '--with-zlib' '--with-mcrypt=/usr/local' '--with-mysql=/usr/local' '--prefix=/usr/local' 'i386--freebsd4.5'




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-24 03:57 UTC] sander@php.net
A client using HEAD tries to figure out wich HTTP-headers it will receive if it will send GET. Those headers can be generated by your script, so the only way to get those headers is executing your script.

If you don't want that, use $_SERVER['REQUEST_METHOD'] or $REQUEST_METHOD to check whether this is a HEAD, GET or POST request.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC