Reputation: 3625
My webpage url is http://example.com/blog/
When I echo it is showing the correct result as blog.
echo $_SERVER['REQUEST_URI']
>>blog
But, when I use in if condition
<?php if($_SERVER['REQUEST_URI']== 'blog') echo 'class="Margincls"';?>
it doesn't return anything, tried with basename and strtolower as well
Upvotes: 0
Views: 5995
Reputation: 1754
I think your site is live. if you use only $_SERVER['REQUEST_URI'] it will work only in localhost.
You can try this.
if (strpos($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '/blog/') == true){
echo "Hello world";
}else{
echo "Hello WOrld 2";
}
Upvotes: 0
Reputation: 140
This should work
<?php if($_SERVER['REQUEST_URI']== '/blog/') echo 'class="Margincls"';?>
Upvotes: 0
Reputation: 732
$_SERVER['REQUEST_URI'] also returns the first forward slash, so you need to check this when equating.
<?php if($_SERVER['REQUEST_URI']== '/blog') echo 'class="Margincls"';?>
Upvotes: 0
Reputation: 463
If your url is http://example.com/blog/
, $_SERVER['REQUEST_URI']
should be /blog/
. I checked on my environment - Apache, PHP 5.6.
Reference: http://php.net/manual/en/reserved.variables.server.php
Upvotes: 1
Reputation: 3594
You are using wrong quotations. Copy and paste this:
<?php if($_SERVER['REQUEST_URI']== 'blog') echo 'class="Margincls"';?>
Upvotes: 0