/    Sign up×
Community /Pin to ProfileBookmark

Homepage detection at subdomain and main domain

I like to detect Homepage using PHP code like:
if($_SERVER[“REQUEST_URI”] != ‘/’ || $_SERVER[“REQUEST_URI”] != ‘/index.php’ || $_SERVER[“REQUEST_URI”] != “” ) {$level “is_front_page”);}else {$level “is_home”);}

Is this correct code or how to be improved?

If I understand code should support
1. [url]www.yourdomain.com[/url]
2. [url]www.yourdomain.com/[/url]
3. [url]www.yourdomain.com/index.php[/url]
4. subdomain.yourdomain.com

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@rootNov 30.2014 — When posting code, wrap you code in forum tags, in this case PHP tags.

[code=php]if($_SERVER["REQUEST_URI"] != '/' || $_SERVER["REQUEST_URI"] != '/index.php' || $_SERVER["REQUEST_URI"] != "" ) {$level "is_front_page");}else {$level "is_home");}[/code]

better still... Format your text...

[code=php]if( $_SERVER["REQUEST_URI"] != '/' ||
$_SERVER["REQUEST_URI"] != '/index.php' ||
$_SERVER["REQUEST_URI"] != "" ) {
$level "is_front_page");
}else {
$level "is_home");
}[/code]


Now do you see what is wrong? Between $level and the opening quote, you have a missing = and also you have a closing bracket after the closing quote that shouldn't be present.

It would be simpler for you to have your conditional use a regular expression to evaluate the string to see if it contains / or /index.php, etc.
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...