Reputation:
PHP:
function is_homepage()
{
}
if(is_homepage())
{
echo 'You are on the homepage';
}
else
{
echo 'You are not on the homepage';
}
Explanation:
is_homepage, should work in all these cases:
Where it shouldn't work:
Upvotes: 2
Views: 95
Reputation: 26861
function is_homepage()
{
return ( ( $_SERVER['HTTP_HOST'] == 'www.domain.com' || $_SERVER['HTTP_HOST'] == 'domain.com') && substr( $_SERVER['REQUEST_URI'], 0, 9 ) == 'index.php' );
}
if(is_homepage())
{
echo 'You are on the homepage';
}
else
{
echo 'You are not on the homepage';
}
Upvotes: 0
Reputation: 73828
It depends of course on how your PHP script is laid out. Though the following solution would work in most cases:
$_SERVER['SCRIPT_NAME'] == '/index.php'
Upvotes: 4
Reputation: 3171
do a
print_r($_SERVER);
and you'll see all the data which will help you achieve this.
I would use
$_SERVER['PHP_SELF']
to identify the file\page I'm currently working with.
Upvotes: 6