略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: apache_lookup_uri

2024-11-14

apache_lookup_uri

(PHP 4, PHP 5, PHP 7, PHP 8)

apache_lookup_uri对指定的 URI 执行部分请求并返回所有有关信息

说明

apache_lookup_uri(string $filename): object|false

本函数对一个 URL 执行部分请求。取得所有有关给定资源的重要信息后就停手。

仅在 PHP 以 Apache 模块运行时,才支持此函数。

参数

filename

被请求的文件名(URI)。

返回值

一个有关 URI 信息的 object。此 object 的属性有:

  • status
  • the_request
  • status_line
  • method
  • content_type
  • handler
  • uri
  • filename
  • path_info
  • args
  • boundary
  • no_cache
  • no_local_copy
  • allowed
  • send_bodyct
  • bytes_sent
  • byterange
  • clength
  • unparsed_uri
  • mtime
  • request_time

失败时返回 false

范例

示例 #1 apache_lookup_uri() 例子

<?php
$info 
apache_lookup_uri('index.php?var=value');
print_r($info);

if (
file_exists($info->filename)) {
    echo 
'file exists!';
}
?>

以上例程的输出类似于:

stdClass Object
(
    [status] => 200
    [the_request] => GET /dir/file.php HTTP/1.1
    [method] => GET
    [mtime] => 0
    [clength] => 0
    [chunked] => 0
    [content_type] => application/x-httpd-php
    [no_cache] => 0
    [no_local_copy] => 1
    [unparsed_uri] => /dir/index.php?var=value
    [uri] => /dir/index.php
    [filename] => /home/htdocs/dir/index.php
    [args] => var=value
    [allowed] => 0
    [sent_bodyct] => 0
    [bytes_sent] => 0
    [request_time] => 1074282764
)
file exists!
add a noteadd a note

User Contributed Notes 3 notes

up
1
tester
14 years ago
bug: with apache 2, apache_lookup_uri("/directory") spits out a warning and fails to return anything.  apache_lookup_uri("/directory/") works.

another bug: virtual("something") forces a header flush.  I know it's documented, but it would be rather wonderful if it didn't do this.  You never ever want to flush headers when you're using virtual() to include a dynamic file such as a PHP or Perl file, which excludes virtual() from being used on most of any website's contents :-(.
up
1
niels dot kootstra at gmail dot com
14 years ago
It's a very usefull function but it doesn't show all outputs. For example I only see:
[status]
[the_request]
[method]
[mtime]
[clength]
[chunked]
[content_type]
[no_cache]
[no_local_copy]
[unparsed_uri]
[uri]
[filename]
[path_info]
[allowed]
[sent_bodyct]
[bytes_sent]
[request_time]
up
0
redbeard at mdjohnson dot nospam dot us
19 years ago
A useful feature is that if you have content negotiation on (Options MultiViews) Apache will resolve the negotiation for you if possible.  Thus www.example.com/blah will resolve to /base/blah.php or /base/blah.html or even /base/blah.en.html as appropriate.

官方地址:https://www.php.net/manual/en/function.apache-lookup-uri.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3