PHP Operator Issue

$WebHost = "website.com";
$WebHostWWW = "websitee.com";

equal to $Webhost OR

if ($_SERVER['SERVER_NAME'] == $WebHost || $WebHostWWW)

Not working when I try to debug, is this coded right?
LVL 3
Computer GuyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GawaiCommented:
See the output first

<?
echo $_SERVER['SERVER_NAME'];
?>
0
Computer GuyAuthor Commented:
It is website. Com.  When I mess with webhostwww. Look at url. I added extra letter
0
Marco GasiFreelancerCommented:
Write this:

if ($_SERVER['SERVER_NAME'] == $WebHost || $_SERVER['SERVER_NAME'] == $WebHostWWW) {
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Dave BaldwinFixer of ProblemsCommented:
I think marqusG is right.  I would normally take it a step further (because it makes it easier for me to see what I'm doing) and add parentheses around each section.

if ( ($_SERVER['SERVER_NAME'] == $WebHost) || ($_SERVER['SERVER_NAME'] == $WebHostWWW) ) {
0
GawaiCommented:
normally that will.return
www.site.com  not just site.com

and i think it should be  === 3 signs

if ( ($_SERVER['SERVER_NAME'] === $WebHost) || ($_SERVER['SERVER_NAME'] === $WebHostWWW) )  

have a look.here

http://php.net/manual/en/reserved.variables.server.php
0
GawaiCommented:
instead of || try with &&
0
Marco GasiFreelancerCommented:
@gawai === check if two values are of the same type and this doesn't seem to be the problem here. In addition if audiotech520 uses && operator he'll get another result since the comparison will return true only if both conditions are true, that is never since if is tru the one can't be true the second :)
0
GawaiCommented:
thanks...i m rusted :(
0
Ray PaseurCommented:
Step #1: Use var_dump($_SERVER) to see if SERVER_NAME is present.  Nothing in PHP guarantees you that the $_SERVER variable will always have the same contents.

Then write your two comparison statements, using the || operator between them, like this:

($_SERVER['SERVER_NAME'] == $WebHost)
||
($_SERVER['SERVER_NAME'] == $WebHostWWW)

Then wrap it all up in an if() statement, with curly-brace control structures like this:

if (
($_SERVER['SERVER_NAME'] == $WebHost)
||
($_SERVER['SERVER_NAME'] == $WebHostWWW)
) { /* DO SOMETHING */ }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Computer GuyAuthor Commented:
Plain and simple, this is what I want to do. I have two sets of code:

If my website is running on my live server, paths will be THIS, else (local server), paths will be THAT

This is good so I can use the same files without having to switch paths. But is it logical to use?

I know that www, test01, test02 are subdomains
<?php
//Where I list all of my domains on the server
$WebHost = "test.com";
//Compensate if user uses "www"
$WebHostWWW = "www.test.com";
//Both subdomains
$SubDomain01 = "test01.test.com";
$SubDomain02 = "test02.test.com";

if (
($_SERVER['SERVER_NAME'] == $WebHost)
||
($_SERVER['SERVER_NAME'] == $WebHostWWW)
||
($_SERVER['SERVER_NAME'] == $Subdomain01)
||
($_SERVER['SERVER_NAME'] == $Subdomain02)
)
{
$AbsolutePath = $_SERVER['DOCUMENT_ROOT']."/";
$SubDomainHomePath = $_SERVER['DOCUMENT_ROOT']."/subdomains/";
$BasePath = "http://www.$WebHost/";
$WebsiteURL = "http://www.$WebHost/";
}
else //Local paths on my local server on my computer
{
$AbsolutePath = $_SERVER['DOCUMENT_ROOT']."/test";
$SubDomainHomePath = "/subdomains/";
$BasePath = "http://localhost/";
$WebsiteURL = "http://localhost/";
}
?>

Open in new window

0
Ray PaseurCommented:
What you're doing is a good idea, but achieving it may be a little more involved than you know right now.  I can't answer this for you but I can show you how to find the answer.  First, please be careful to get the terminology right. This link shows the words and their definitions.  Subdirectories are often called "paths" in the PHP online docs.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28261164.html#a39576454

Next run the following script (shown here in its entirety) on each of your installations in each of the subdomains and subdirectories, as well as the web root directory (note the terminology carefully).  Print the outputs so you can sit down in a chair and look at all of them at the same time.  Look for consistencies and differences in the SERVER vars.

<?php echo '<pre>'; var_dump($_SERVER);

Open in new window

Then consult with your web host about the organization of the request and any URL rewriting that may be in place.  This matters because some hosting companies will be "helpful" to you by rewriting all domain.com requests to www.domain.com or vice versa.  Consider what will happen if a client comes to your site with FFF.domain.com -- will your .htaccess rewrite that request?

Be aware that HTTP cookies, including the session cookie, are by default tied to a single subdomain and a single subdirectory.  You can set cookies that work across subdomains and subdirectories if you look at the options in setcookie().

The path to your data base server, even if it's on localhost, may vary from one installation to the next, so check that, too.

Check also for the SERVER vars in any CRON or email PIPE scripts.  It will almost certainly be different from the www root.

If you ever change hosting companies, you should plan on rechecking everything.

And finally, good luck! ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.