Richieaaron Morris
Richieaaron Morris

Reputation: 43

PHP conditional redirect always redirects to the same page

I have two domains and need to make a entry script so i can determine which site the user is coming for and redirect them to the correct part of the site but it just directs to the first link

<?php

if($_SERVER['HTTP_HOST'] == 'neonbacon.com' || 'www.neonbacon.com') 
{
header("Location: http://neonbacon.com/client");
}
else if($_SERVER['HTTP_HOST'] == 'scarletgamers.com' || 'www.scarletgamers.com')
{
header("Location: http://scarletgamers.com/home");
}else
{
echo 'Error 1';
}

?>

Upvotes: 0

Views: 793

Answers (1)

Thomas Kelley
Thomas Kelley

Reputation: 10302

It's an order-of-operations issue. You are asking if either

$_SERVER['HTTP_HOST'] == 'neonbacon.com' or 'www.neonbacon.com'

...is true. The second one will always be true, since it's just a string. So therefore, it'll always execute that if block.

Try this:

if($_SERVER['HTTP_HOST'] == 'neonbacon.com' || $_SERVER['HTTP_HOST'] == 'www.neonbacon.com')

and:

else if($_SERVER['HTTP_HOST'] == 'scarletgamers.com' || $_SERVER['HTTP_HOST'] == 'www.scarletgamers.com')

Upvotes: 2

Related Questions