DrewRock Posted June 28, 2011 Share Posted June 28, 2011 I'm stuck! I am somewhat new to PHP and I haven't been able to solve this problem because it seems that I cannot phrase a google search correctly. I have a friend with a pizza restaurant that I am helping set up his sites. He has a main site, which we will call http://specialpizza.com. He also has a 12 other different domains, on GoDaddy, that all forward with masking to his main site. The masking basically loads the main site in an iFrame. Example: http://mainstreetspecialpizza.com forwards to a page with http://specialpizza.com in an iFrame while the URL remains http://mainstreetspecialpizza.com in the browser's address bar. When discussing his needs with him, he told me that he wanted all the sites to be basically the same except he wanted each site to reflect the URL in its content. I figured I could have all 12 domains forward to one page and simply populate the changing site names with variables dependent on the current URL. I just can't seem to figure out how to make the variable "$site" have a different value for each URL. I understand that the if/else statement is pretty messed up (single/double quotes and such). I think I am on the right track here but I am not sure. PLEASE HELP! EXAMPLE: <html><head> <?php //GET CURRENT URL 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; } //BEGIN IF ELSE STATEMENT if (curPageURL() == 'http://specialpizza.com/') { echo "$site='Special Pizza' "; } if (curPageURL() == 'http://mainstreetspecialpizza.com/') { echo "$site= 'Main Street Pizza' "; if (curPageURL() == 'http://elmstreetspecialpizza.com/') { echo "$site= 'Elm Street Pizza' "; } else{ echo 'doesnt work'; } ?> <title><?php echo $site; ?></title> </head> <body> <h1>Welcome to <?php echo $site; ?></h1> <p>Text text text <?php echo $site; ?> text text text text text text text text text text text text <?php echo $site; ?> text text text text text text </p> </body> </html> THANK YOU!!!! Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/ Share on other sites More sharing options...
Maq Posted June 28, 2011 Share Posted June 28, 2011 In the future, please place OR tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/#findComment-1235896 Share on other sites More sharing options...
DrewRock Posted June 28, 2011 Author Share Posted June 28, 2011 THANKS! Will do! Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/#findComment-1235898 Share on other sites More sharing options...
WebStyles Posted June 28, 2011 Share Posted June 28, 2011 here's a simplified version, I'm sure you can figure out the rest from here: <html><head> <?php //BEGIN IF ELSE STATEMENT $url = $_SERVER["SERVER_NAME"]; $site = ''; if ($url == 'specialpizza.com') $site = 'Special Pizza'; if ($url == 'mainstreetspecialpizza.com') $site = 'Main Street Pizza'; if ($url == 'elmstreetspecialpizza.com') $site = 'Elm Street Pizza'; ?> <title><?php echo $site; ?></title> </head> <body> <h1>Welcome to <?php echo $url; ?></h1> <p>Text text text text text text text text text text text text text text text <?php echo $site; ?> text text text text text text </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/#findComment-1235902 Share on other sites More sharing options...
fugix Posted June 28, 2011 Share Posted June 28, 2011 a quick revision to the code above to 3 lines if ($url == 'www.specialpizza.com') $site = 'Special Pizza'; if ($url == 'www.mainstreetspecialpizza.com') $site = 'Main Street Pizza'; if ($url == 'www.elmstreetspecialpizza.com') $site = 'Elm Street Pizza'; $_SERVER['SERVER_NAME'] outputs www. included in the server name Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/#findComment-1235907 Share on other sites More sharing options...
WebStyles Posted June 28, 2011 Share Posted June 28, 2011 hmmm... forgot about that detail cause I tested on 'localhost'... Thanks Fugix. Maybe you'll want to use strpos() to check the names, since visitors might or might not include the www., or use str_replace("www.","",$url); to remove it... or something. Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/#findComment-1235914 Share on other sites More sharing options...
JonnoTheDev Posted June 28, 2011 Share Posted June 28, 2011 I have a friend with a pizza restaurant that I am helping set up his sites. He has a main site, which we will call http://specialpizza.com. He also has a 12 other different domains, on GoDaddy, that all forward with masking to his main site. The masking basically loads the main site in an iFrame. This is silly. iFrames are from the far reaches of hell and died back in 1999. You should simply redirect all your domains to the main website via a 301. You can add a parameter onto the url that specifies the originating site and use that to change the header by storing in a session or whatever. However, if you want each domain without a redirect, and by just changing the title of the site for each, are asking Google to penalize you for duplicate content across multiple domains! The sites will end up in the sandbox for sure. What you should do is point the A records of each domain to the web server that hosts the site. Set these domains up the the Apache configuration and point them all at the main website's document root. Each domain will serve the same website, however you can now use the following to change the content of your site dependent on each domain: $_SERVER['HTTP_HOST'] So <?php /* you could put all this in a common include */ $sites['www.specialpizza.com'] = array('title' => 'Special Pizza', 'description' => 'Some text'); $sites['www.mainstreetspecialpizza.com'] = array('title' => 'Main Street Pizza'); $sites['www.elmstreetspecialpizza.com'] = array('title' => 'Elm Street Pizza'); $mysite_data = $sites[$_SERVER['HTTP_HOST']]; /* index file */ echo $mysite_data['title']; ?> Personally, I would forget what you are trying to do and simply redirect all your domains to the main website as suggested above. Maybe you'll want to use strpos() to check the names, since visitors might or might not include the www., or use str_replace("www.","",$url); to remove it... or something. You should always redirect non www to a www address or vica versa. You should never have both. Quote Link to comment https://forums.phpfreaks.com/topic/240621-setting-a-variable-based-upon-url/#findComment-1235916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.