Re: execute a script on access to a directory
| From: | Doug Granzow | Date: | Fri, 07 Sep 2001 19:38:45 +0000 |
| Subject: | Re: execute a script on access to a directory | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66456@lists.php.net to get a copy of this message | ||
You can make "go" the name of your PHP script, then put this in your Apache
config:
<Location /go>
ForceType application/x-httpd-php
</Location>
Now in your "go" script, you have it do whatever you wanted it to do, then
use an include to load the "getit" script.
Here's an except from my equivalent of your 'go' script:
// $PATH_INFO = the rest of the URI after dmb/
// (in "http://www.minarets.net/dmb/trading/toptraders")
// remove anything other than letters, numbers, dots, underscores,
// and dashes, and put into an array
// for example "trading/toptraders" will be an array consisting
// of "trading" ($args[1]) and "toptraders" ($args[2]). The / is
discarded.
ereg("(^[-_.\/a-zA-Z0-9]*$)", $PATH_INFO, $arg);
$args = split( "/", $arg[1]);
$file = "include/" . $args[1] . ".inc";
if (file_exists($file)) {
include "$file";
} else {
?>
404 not found
<?
}
Note the line that sets the value of $file. In this case, your 'getit'
script is in the "include" directory, not the "go" directory. (You can't
have a directory named 'go' since you now have a script named 'go'.)
Doug Granzow
dig@cynosure.net
"Enrique Vadillo" <enrique_vadillo@hotmail.com> wrote in message
news:F10kUj8rCTKhCRXevbJ00009c43@hotmail.com...
> Hi,
>
> I would like to know how i can force a PHP script to be
> executed everytime a certain directory is accessed, for
> example in http://domain.com/go/getit the presence of the
> /go/ directory would force a PHP script to be executed
> prior to any operation.
>
> Do i need to play with rewriting urls in Apache or is
> there any other cleaner method (that would not require
> rewriting URLs) to achieve this? i'd hate to have to
> rewrite URLs...
>
> thanks.
>
> Enrique-
>
>
> _________________________________________________________________
> Descargue GRATUITAMENTE MSN Explorer en
> http://explorer.msn.es/intl.asp
>