Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Apache-specific Functions : apache_lookup_uri

apache_lookup_uri

Perform a partial request for the specified URI and return all info about it (PHP 4, PHP 5)
object apache_lookup_uri ( string filename )

Example 204. apache_lookup_uri() example

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

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

The above example will output something similar to:

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!

Code Examples / Notes » apache_lookup_uri

trejkaz

Apparently on PHP 4.2, this function returns an array instead of an object.
That being the case, the example code above would translate to:
<?php
$info = apache_lookup_uri('index.php?var=value');
print_r($info);
if (file_exists($info['filename'])) {
  echo 'file exists!';
}
?>
A means of making this transparent so that the object syntax works, is left as an exercise for the reader. ;-)


redbeard

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.

Change Language


Follow Navioo On Twitter
apache_child_terminate
apache_get_modules
apache_get_version
apache_getenv
apache_lookup_uri
apache_note
apache_request_headers
apache_reset_timeout
apache_response_headers
apache_setenv
ascii2ebcdic
ebcdic2ascii
getallheaders
virtual
eXTReMe Tracker