检查当前网址

时间:2010-08-02 16:24:09

标签: php url

我们有网址:

  

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

我如何知道当前网址(打开的网页)中是否存在/posters/fixed/

像:

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

感谢。

3 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分:3)

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

答案 2 :(得分:1)

如果您想检查文件是否存在,则只需拨打file_exists()

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

我把PHP文件复制到服务器根目录下。

如果要验证用于访问您报告的文件的URL(假设它们实际上是PHP文件,并且您将代码放在其中以验证用于访问它们的URL,则以下代码可以正常工作:

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

如果您的意思是其他内容,那么请延伸问题,以便更清楚您的意思。