Link to home
Start Free TrialLog in
Avatar of Computer Guy
Computer Guy

asked on

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?
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

See the output first

<?
echo $_SERVER['SERVER_NAME'];
?>
Avatar of Computer Guy
Computer Guy

ASKER

It is website. Com.  When I mess with webhostwww. Look at url. I added extra letter
Avatar of Marco Gasi
Write this:

if ($_SERVER['SERVER_NAME'] == $WebHost || $_SERVER['SERVER_NAME'] == $WebHostWWW) {
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) ) {
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
instead of || try with &&
@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 :)
thanks...i m rusted :(
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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.
https://www.experts-exchange.com/questions/28261164/PHP-Operator-Help.html?anchorAnswerId=39576454#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