Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Warning: Director::protocolAndHost() lacks sufficient information - HTTP_HOST not set


Go to End
Reply


9 Posts   2892 Views

Avatar
Joril

Community Member, 5 Posts

28 March 2011 at 9:11pm

Hi everyone!
Our company site is built with Silverstripe 2.4.4 and we are very happy with it, but we're having a small problem... Sometimes we are "visited" by some script/bot that (I think) scans the 'net looking for buffer overflows, and every time this results in 10 warning e-mails being sent to the site admin. Every mail has subject "Warning: Director::protocolAndHost() lacks sufficient information - HTTP_HOST not set."
I tried adding to mysite/_config.php the following:

global $_FILE_TO_URL_MAPPING;
$_FILE_TO_URL_MAPPING['/var/www/cms'] = 'http://our.site.com';

but the problem is still there... Any hint?

Avatar
Joril

Community Member, 5 Posts

15 April 2011 at 7:20pm

I ended up adding a mod_security rule to Apache:

SecRule REQUEST_METHOD "!^(?:GET|HEAD|OPTIONS|POST|CONNECT)$"

Avatar
slith

Community Member, 7 Posts

23 August 2011 at 10:17am

i fixed the problem by setting register_globals = On in php.ini

Avatar
Joril

Community Member, 5 Posts

29 August 2011 at 6:57pm

Sadly that command is deprecated (http://php.net/manual/en/security.globals.php) and can cause security problems :/

Avatar
martimiz

Forum Moderator, 1202 Posts

31 August 2011 at 1:21am

Edited: 31/08/2011 1:21am

Looking at the protocolAndHost() function, it seems that it doesn't use the HTTP_HOST var if an $alternateBaseURL is given. So you can set the website root from mysite/_config.php?

Director::setBaseURL('http://our.site.com/');

As long as it's a 'simple' site that has the one root, it stills seems to work fine... So I don't know if there's anything against using this, apart from obvious issues on moving the site?

Avatar
Joril

Community Member, 5 Posts

31 August 2011 at 1:42am

I'll try that, thank you :)

Avatar
Tama

Community Member, 135 Posts

2 July 2015 at 8:25am

I've run into this error as well and it's doing my head in.

When trying to view pages in the CMS I get the following error in silverstripe.log:

[02-Jul-2015 04:48:35] Warning at framework/control/Director.php line 473: Director::protocolAndHost() lacks sufficient information - HTTP_HOST not set.

So I had a look at the code in question:

if(isset($_SERVER['HTTP_HOST'])) {
			return Director::protocol() . $_SERVER['HTTP_HOST'];
		} else {
			global $_FILE_TO_URL_MAPPING;
			if(Director::is_cli() && isset($_FILE_TO_URL_MAPPING)) $errorSuggestion = '  You probably want to define '.
				'an entry in $_FILE_TO_URL_MAPPING that covers "' . Director::baseFolder() . '"';
			else if(Director::is_cli()) $errorSuggestion = '  You probably want to define $_FILE_TO_URL_MAPPING in '.
				'your _ss_environment.php as instructed on the "sake" page of the doc.silverstripe.com wiki';
			else $errorSuggestion = "";
			
			user_error("Director::protocolAndHost() lacks sufficient information - HTTP_HOST not set."
				. $errorSuggestion, E_USER_WARNING);
			return false;
			
		}

The issue seems to be that the code can't read HTTP_HOST. However if I setup a simple flat PHP file like this:

<?php
echo $_SERVER['HTTP_HOST']."<hr/>";

if(isset($_SERVER['HTTP_HOST'])) {
  echo "true";
} else {
  echo "false";			
}

It returns:

www.mysite.com
----------------------------------------------------------------------------------------
true

Which seems to mean that HTTP_HOST is available outside of Silverstripe, but not inside.

Any ideas what's going on?

Avatar
Pyromanik

Community Member, 418 Posts

3 July 2015 at 10:45am

Using Apache?
Could be something to do with rewrite or some other .htaccess directive.

Probably not, just pointing out places to start looking tho.

Go to Top