如果 url 包含以下内容,则不要显示此内容 [英] Don't show this if the url contains the following

查看:21
本文介绍了如果 url 包含以下内容,则不要显示此内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 div,如果访问者加载了某个 URL,我不想加载它.

I have a simple div which I don't want to load if the visitor loads up a certain URL.

看起来像这样:

<?php
if( stristr($_SERVER['PHP_SELF'], 'blog') == FALSE  )
{

echo "<div id="stuff"></div>";

}
?>

问题是...它不起作用...当我加载 www.url.com/blog 时,div#stuff 仍然显示.

Problem is... it doesn't work... when I load up www.url.com/blog the div#stuff still shows.

我只是睡眠不足还是上述方法应该有效?如果 url 包含 blog,如果没有 div 显示,你会怎么做?

Am I just lacking sleep or should the above work? What would you do to not have a div display if the url contains blog ?

推荐答案

尝试 $_SERVER['REQUEST_URI'] 代替:

Try $_SERVER['REQUEST_URI'] instead:

if (substr($_SERVER['REQUEST_URI'], 0, 5) !== '/blog') {
    echo '<div id="stuff"></div>';
}

REQUEST_URI 包含请求的 URI 路径和查询,而不仅仅是像 PHP_SELF 那样当前正在执行的脚本的文件名.

REQUEST_URI contains the requested URI path and query and not just the filename of the currently executing script like PHP_SELF does.

这篇关于如果 url 包含以下内容,则不要显示此内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆