Reputation: 3108
I need to see if the current page a user is on is the main page of the website, i.e. there is nothing after the base url.
I'm doing this to exclude some code off the main page.
I asked this question is Javascript, but would like to implement it in PHP
Upvotes: 0
Views: 301
Reputation: 933
This will probably give you what you are looking for:
$is_home = $_SERVER[ 'REQUEST_URI' ] === '/' ? true : false;
Upvotes: 2
Reputation: 9172
The following should do the trick:
if (empty($_SERVER['QUERY_STRING'])) {
// no params
}
Upvotes: 0
Reputation: 10303
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
This should give you the url of the current page, when you have this you can check it against the home url.
Upvotes: 1