Is there a way for php to know the way?

I can use $_ SERVER ["HTTP_HOST"] to know the current web address
and also $_ SERVER [" PHP_SELF"] to know which file I am loading now
for example, when I am in index.php
, he will show / index.php
if I am in admin/index.php
, he will show / admin/index.php
what I want to implement is

.

run a script as long as there is a / admin/*.php on the road
, but how can I tell if it is down under / admin/*.php?
how do I catch / admin/ ? Do not decide which .php, just judge the file name before it

PS I want to use the basename (_ _ FILE__) series, but my local side is one location, and the server side is another, so I have to make multiple decisions, which is not easy to use. _ SERVER is the most monotonous, skipping the root root directory directly, but it doesn"t have the function of just grabbing files.

Mar.29,2021


if(preg_match('-sharp/admin/-sharp',$_SERVER['SCRIPT_NAME'])) {
    echo 'admin';
}

if you are jumping to the specified php file, refer to the nginx redirect configuration. If you want to execute a specific function before or after execution of the requested php file, match url

before entry or end
Menu