Page 1 of 1

PHP Notice: Undefined index:

Posted: Mon Oct 31, 2011 8:43 pm
by werepair
getting 2 error messages in my error log.

2011-10-31 10:26:31 - PHP Notice: Undefined index: HTTP_HOST in /home/xxxxxxx/public_html/index.php on line 179
2011-10-31 10:26:31 - PHP Notice: Undefined index: HTTP_HOST in /home/xxxxxxx/public_html/system/library/currency.php on line 45

any idea ?

line 44 currency.php

Code: Select all

if ((!isset($this->request->cookie['currency'])) || ($this->request->cookie['currency'] != $currency)) {
	  		setcookie('currency', $currency, time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
    	}
  	}

line 178 index.php

Code: Select all

if (!isset($request->cookie['language']) || $request->cookie['language'] != $code) {	  
	setcookie('language', $code, time() + 60 * 60 * 24 * 30, '/', $request->server['HTTP_HOST']);
}
Best Regards

Re: PHP Notice: Undefined index:

Posted: Tue Nov 01, 2011 1:36 pm
by wernerrenrew
Hi,

Change HTTP_HOST to SERVER_NAME to prevent problems with client not setting HTTP_HOST

Or just ignore those clients probly bad spiders :laugh:

Re: PHP Notice: Undefined index:

Posted: Tue Nov 01, 2011 3:40 pm
by uksitebuilder
Be careful using SERVER_NAME, if this is not correctly set-up in your server config then it wont work

Likewise if you run multi stores then you shouldn't use SERVER_NAME

If HTTP_HOST is missing it either means the (a) the client is using a very old browser, (b) the bot doesn't send it or (c) the site is being accessed by it's IP Address rather than the domain name

Re: PHP Notice: Undefined index:

Posted: Tue Nov 01, 2011 4:38 pm
by wernerrenrew
uksitebuilder wrote:Be careful using SERVER_NAME, if this is not correctly set-up in your server config then it wont work

Likewise if you run multi stores then you shouldn't use SERVER_NAME

If HTTP_HOST is missing it either means the (a) the client is using a very old browser, (b) the bot doesn't send it or (c) the site is being accessed by it's IP Address rather than the domain name
Why would a multi store setup be a problem it's the cookie domain set most likely to the www. subdomain in case of multi domain setup in my opinion SERVER_NAME would be the better choice it could be set by the server (ofcourse the best solution in case of multi setup is define the cookie domein and set it to .my-domain.com), also it's very unlikely that this is not configured correctly but if that's the case it's time for a support ticket better yet find another host or someone to configure your dedicated server correctly :D

Advice just ignore those errors it's not your customers generating them so why change any core files.

Re: PHP Notice: Undefined index:

Posted: Wed Nov 02, 2011 3:53 am
by werepair
uksitebuilder wrote:Be careful using SERVER_NAME, if this is not correctly set-up in your server config then it wont work

Likewise if you run multi stores then you shouldn't use SERVER_NAME

If HTTP_HOST is missing it either means the (a) the client is using a very old browser, (b) the bot doesn't send it or (c) the site is being accessed by it's IP Address rather than the domain name
Thanks for the input
not sure whats the problem is to be honest, the site is a mirror image of another site with a different logo and name, all the products are the same yet no errors on the other site.

Best Regards

Re: PHP Notice: Undefined index:

Posted: Tue Aug 21, 2012 10:34 pm
by Qphoria
I've seen recommendations to use getenv('HTTP_HOST') instead of $_SERVER['HTTP_HOST']. This issue just started recently on my webhost too.. so I'll keep you updated

Re: PHP Notice: Undefined index:

Posted: Wed Aug 22, 2012 5:46 am
by dave310
I am facing the same error problem. Anyone found any solution? we are not on multishop. so whats with "change to server name???" Can someone guide please.

Re: PHP Notice: Undefined index:

Posted: Wed Aug 22, 2012 11:43 pm
by Qphoria
dave310 wrote:I am facing the same error problem. Anyone found any solution? we are not on multishop. so whats with "change to server name???" Can someone guide please.
Based on my post above.. you can change your index.php file like this.

1. EDIT: index.php

2. FIND THIS BLOCK:

Code: Select all

// Store
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} 
3. REPLACE WITH THIS BLOCK:

Code: Select all

// Store
$http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : getenv('HTTP_HOST');

if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $http_host) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $http_host) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
}
 

Re: PHP Notice: Undefined index:

Posted: Fri Sep 07, 2012 9:46 am
by moneycarlo
I'm still seeing this error in my log after i've changed my index.php.
Other Ideas?

Re: PHP Notice: Undefined index:

Posted: Tue Oct 16, 2012 5:51 pm
by eddie_d
Qphoria being as you are the opencart GOD and you have/had this problem any news on error I have exhausted all suggested solutions I found on the web, even scrapped my site and done fresh install with 1.5.4.1 thinking that will fix it. I don't think it is causing major problems but i hate seeing errors in the log.

Regards

Eddie

Re: PHP Notice: Undefined index:

Posted: Tue Oct 16, 2012 6:01 pm
by eddie_d
here are my errors

2012-10-16 8:26:13 - PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/xxxxx/public_html/index.php:49) in /home/xxxx/public_html/system/library/session.php on line 11
2012-10-16 8:26:13 - PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/xxxxx/public_html/index.php:49) in /home/xxxxxx/public_html/system/library/session.php on line 11
2012-10-16 8:26:13 - PHP Notice: Undefined index: HTTP_HOST in /home/xxxxxx/public_html/index.php on line 177
2012-10-16 8:26:13 - PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxx/public_html/index.php:49) in /home/xxxxx/public_html/index.php on line 177
2012-10-16 8:26:13 - PHP Notice: Undefined index: HTTP_HOST in /home/xxxxxx/public_html/system/library/currency.php on line 45
2012-10-16 8:26:13 - PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxx/public_html/index.php:49) in /home/xxxx/public_html/system/library/currency.php on line 45

regards

eddie

Re: PHP Notice: Undefined index:

Posted: Fri Oct 26, 2012 10:30 pm
by bobwhite
I am getting similar errors:
2012-10-19 22:31:32 - PHP Notice: Undefined index: HTTP_HOST in /public_html/index.php on line 179
2012-10-19 22:31:32 - PHP Warning: Cannot modify header information - headers already sent by (output started at /public_html/index.php:49) in /public_html/index.php on line 179
2012-10-19 22:31:32 - PHP Notice: Undefined index: HTTP_HOST in /public_html/system/library/currency.php on line 45
2012-10-19 22:31:32 - PHP Warning: Cannot modify header information - headers already sent by (output started at /public_html/index.php:49) in /public_html/system/library/currency.php on line 45

Thanks,

Re: PHP Notice: Undefined index:

Posted: Wed Jan 23, 2013 3:01 pm
by stringtokenizer
I am having a same problem.

2013-01-22 14:22:31 - PHP Notice: Undefined index: HTTP_HOST in /home/public_html/system/library/currency.php on line 45

Any idea ?

Re: PHP Notice: Undefined index:

Posted: Sat Mar 09, 2013 5:31 am
by HorseMagic
We have same problem and we have the above code from Qphoria in index file already.

2013-03-08 3:16:29 - PHP Notice: Undefined index: HTTP_HOST in /home/xxxxxxx/public_html/index.php on line 179
2013-03-08 3:16:29 - PHP Notice: Undefined index: HTTP_HOST in /home/xxxxxxx/public_html/system/library/currency.php on line 45

I am guessing by what is said in these posts it is not an error to worry about?