• 0
Sign in to follow this  
Followers 0

HTTP_HOST changing in functions.php


Question

Posted · Report post

I am getting variable results from the $_SERVER['HTTP_HOST'] variable in the functions.php file of our child theme.

Let me explain our setup and then I'll explain the issue. We are running WP 3.5.2 on Nginx with PageLines 2.4 as our parent theme and a handful of plugins that I can detail if necessary. Our virtual host is set to answer to *.salesgenie.com as we have several private label subdomains that will change the branding of the site. www.salesgenie.com will be the generic domain but att.salesgenie.com is an example of a branded subdomain.

So I need to be able to detect the subdomain the client calls with which I am trying to get with $_SERVER['HTTP_HOST']. The issue is that $_SERVER['HTTP_HOST'] is accurate the first time a client comes to their domain but reverts to the $_SERVER['SERVER_NAME'] value after that either on page reload or navigation to any other page.  I have gone through disabling all plugins in our test environment and that made no difference but when I switched to the TwentyTwelve them the HTTP_HOST worked just fine.  I tried upgrading to PL 2.4.4 and it had the same problem.

To test this I've got a function logging the $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] to a cookie called CmsCookie and you can test it by going to cms.salesgenie.com (the CNAME is working) and both variables will read cms.salesgenie.com. But if you modify your host file to point att.salesgenie.com at 54.208.87.200 then you can test att.salesgenie.com and the cookie will be correct the first time you hit a page, but if you reload, both server name and host will be cms.salesgenie.com

Any ideas what in Pagelines is changing the HTTP_HOST?

Share this post


Link to post
Share on other sites

10 answers to this question

  • 0

Posted · Report post

So any ideas on what in PL is rewriting the HTTP_HOST?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

There is no code to rewrite HTTP_HOST anywhere in PageLines Framework.

 

$_SERVER['HTTP_HOST'] is used twice to get the current URL, but only to read it, the superglobal is never changed.

 

Maybe look into the way your using sessions/cookies. Perhaps your PHP install is setup wrong.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Well, as I said before, the exact same code works when I put it into the 2012 theme and turn off Pagelines.  So the code works fine, until PL is activated.  I even get the same behavior when using pl_get_uri( TRUE ).  

 

setcookie('CmsCookie', $_SERVER['SERVER_NAME'].' - '.$_SERVER['HTTP_HOST'].' - '.pl_get_uri( TRUE ) , 0, '/', 'salesgenie.com', 0);

 

On the first visit HTTP_HOST and pl_get_uri return the correct URI, the one typed into the browser, but upon reloading the page or navigating to another page they both return the SERVER_NAME.

 

HTTP_HOST works just fine when put into the functions.php of 2012 and turning off PL.  Disabling all plugins made no difference.  It breaks even when I activate the base PL theme and not our child theme and it is a fresh download of PL 2.4.4 from yesterday.  So something in PL ends up changing the HTTP_HOST.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

How are you changing the site_url etc? is this 2 different wordpress installs?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Both site and home url are set in the DB, via the admin panels > settings > general.

 

They are not set in the wp-config file

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

no i mean your loading the same site with 2 different subdomains, either its the same site and your changing the urls dynamically, or you have one url set in the configfile and your expecting it to work with any subdomain, or its 2 different wordpress installs?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Same wordpress install for all subdomains.  The virtual host is set to a wildcard *.salesgenie.com directed to the test-cms.salesgenie.com directory.  So any subdomain is directed to the same wordpress installation.  The only url rewriting is being done in jQuery to change all links from the base www.salesgenie.com to whatever the calling subdomain is i.e. att.salesgenie.com

 

Our test environment is test-cms.salesgenie.com and that CNAME is currently set up.  Eventually we will point all branded subdomains to the same WP installation but for testing for now I modify my hosts file to set att.salesgenie.com to point to that same server 

 

54.208.67.170 att.salesgenie.com

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Is that even supported in wordpress? I thought multisite was for multiple subdomains?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Well it works just fine with a standard installation of WP and the default theme. 

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

So no suggestions on what to look into or a work around?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0