Don't show this if the url contains the follow

2020-05-06 06:59发布

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

It looks like this:

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

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

}
?>

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

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 ?

标签: php wordpress
3条回答
对你真心纯属浪费
2楼-- · 2020-05-06 07:26

OP's version works for me. Provided that you fix the echo() syntax error.

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

tested on PHP Version 5.2.9

查看更多
等我变得足够好
3楼-- · 2020-05-06 07:31

try using the === operator as per the 2nd example on:

http://us2.php.net/manual/en/function.stristr.php

查看更多
我只想做你的唯一
4楼-- · 2020-05-06 07:32

Try $_SERVER['REQUEST_URI'] instead:

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

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

查看更多
登录 后发表回答