Check current URL

2019-08-18 03:47发布

We have urls:

http://site.com/movies/posters/ID.html
http://site.com/movies/posters/fixed/ID.html

How do I know if /posters/fixed/ is present in the current url (on opened page)?

Like:

if ("/posters/fixed/" present) {
    $match_fixed = true;
}

Thanks.

标签: php url
3条回答
干净又极端
2楼-- · 2019-08-18 03:52

if (preg_match("//posters/fixed/", $_SERVER['REQUEST_URI'])) ...

查看更多
不美不萌又怎样
3楼-- · 2019-08-18 03:57
if(strpos($_SERVER['REQUEST_URI'],"/movies/posters/fixed/")===0){
    //true
}
查看更多
相关推荐>>
4楼-- · 2019-08-18 04:08

If you want to check if a file exists, then you can simply call file_exists().

if (file_exists("./movies/posters/fixed/ID.html") && is_file("./movies/posters/fixed/ID.html")) {
  $match_fixed = true;
}

I take the PHP file is copied in the server root directory.

If you want to verify the URL used to access the files you reported (assuming they are really PHP files, and you put the code inside them to verify the URL used to access them, then the following code works:

if (strpos($_SERVER['REQUEST_URI'],"/posters/fixed/") === 0) {
  $match_fixed = true;
}

If you meant something else, then extend the question so it's clearer what you mean.

查看更多
登录 后发表回答