Jump to content


Photo
- - - - -

HTTP_HOST changing in functions.php

functions.php

  • Please log in to reply
10 replies to this topic

#1 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 07 August 2013 - 07:23 PM

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 

Please Login or Register to see this Hidden Content

 (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?



#2 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 08 August 2013 - 04:23 PM

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



#3 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 08 August 2013 - 06:01 PM

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.



#4 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 08 August 2013 - 07:22 PM

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.



#5 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 08 August 2013 - 07:48 PM

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



#6 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 08 August 2013 - 08:06 PM

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



#7 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 08 August 2013 - 08:08 PM

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?



#8 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 08 August 2013 - 08:13 PM

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



#9 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 08 August 2013 - 08:21 PM

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



#10 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 08 August 2013 - 09:22 PM

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



#11 infogroupsmb

infogroupsmb

    Advanced Member

  • Members

  • 37 posts
  • Country: Country Flag

Posted 09 August 2013 - 02:26 PM

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







Also tagged with one or more of these keywords: functions.php