I know why this happens and I know what to fix, but I don’t know where to fix it. When Magento logs IP address using REMOTE_ADDR it logs Mosso’s Load Balancers.
So I was wondering if there is an easy fix to change the way Magento Logs IP address for “Online Customers” and when making a transaction? The proper way to log the IP on Mosso when an account has SSL is to use HTTP_X_FORWARDED_FOR (http://help.mosso.com/article.php?id=180) so the first and only thing I’ve tried so far was change System>Config>Web>Session Validation Settings to not validate using REMOTE_ADDR. Of course that didn’t change the way it logs the IP during a transaction. Where can I change the way Magento Logs IP addresses?
I did a backup then did a find and replace for REMOTE_ADDR to HTTP_X_FORWARDED. I emptied the sessions and cache in my browser and in Magento. The exact find and replace I did is the following:
$_SERVER[’REMOTE_ADDR’]
to
$_SERVER[’HTTP_X_FORWARDED’]
It seems to still be logging the Load Balancer IP address. So I guess I have two questions.
1. Is there a chance that Mosso, Magento or my Browser is somehow serving up something old?
2. Are there any cases (that you know of) that I should have left the code in Magento as $_SERVER[’REMOTE_ADDR’]?
I still need help with this, if anyone on Here has installed Magento on Mosso you must have run into this problem. I used Notepad++ to find all variations of “REMOTE_ADDR” in .php, .php3, phtml, & .xml files below are the results. I’m not sure I can do a simple find and replace for all instances of “REMOTE_ADDR” and help would be appreciated.
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Adminhtml\Block\Customer\Online\Grid.php (1 hits)
Line 104: ‘index’=>’remote_addr’,
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Core\etc\config.xml (2 hits)
Line 235: <use_remote_addr>1</use_remote_addr>
Line 235: <use_remote_addr>1</use_remote_addr>
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Core\etc\system.xml (3 hits)
Line 1064: <use_remote_addr translate="label">
Line 1065: <label>Validate REMOTE_ADDR</label>
Line 1072: </use_remote_addr>
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Core\Model\Session\Abstract\Varien.php (7 hits)
Line 34: const VALIDATOR_REMOTE_ADDR_KEY = ‘remote_addr’;
Line 34: const VALIDATOR_REMOTE_ADDR_KEY = ‘remote_addr’;
Line 246: * Use REMOTE_ADDR in validator key
Line 327: if ($this->useValidateRemoteAddr() && $sessionData[self::VALIDATOR_REMOTE_ADDR_KEY] != $validatorData[self::VALIDATOR_REMOTE_ADDR_KEY]) {
Line 327: if ($this->useValidateRemoteAddr() && $sessionData[self::VALIDATOR_REMOTE_ADDR_KEY] != $validatorData[self::VALIDATOR_REMOTE_ADDR_KEY]) {
Line 353: self::VALIDATOR_REMOTE_ADDR_KEY => ‘’,
Line 361: $parts[self::VALIDATOR_REMOTE_ADDR_KEY] = (string)$_SERVER[’HTTP_X_FORWARDED_FOR’];
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Core\Model\Session\Abstract.php (4 hits)
Line 36: const XML_PATH_USE_REMOTE_ADDR = ‘web/session/use_remote_addr’;
Line 36: const XML_PATH_USE_REMOTE_ADDR = ‘web/session/use_remote_addr’;
Line 89: * Use REMOTE_ADDR in validator key
Line 95: $use = Mage::getStoreConfig(self::XML_PATH_USE_REMOTE_ADDR);
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Log\Model\Mysql4\Customer.php (1 hits)
Line 113: ->joinInner($this->_visitorInfoTable, $this->_visitorTable.’.visitor_id=’.$this->_visitorInfoTable.’.visitor_id’, array(’http_referer’, ‘remote_addr’))
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Log\Model\Mysql4\Visitor.php (1 hits)
Line 110: ‘remote_addr’ => $visitor->getRemoteAddr(),
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Log\Model\Visitor.php (3 hits)
Line 69: ‘remote_addr’ => empty($s[’REMOTE_ADDR’]) ? ‘’ : ip2long($s[’REMOTE_ADDR’]),
Line 69: ‘remote_addr’ => empty($s[’REMOTE_ADDR’]) ? ‘’ : ip2long($s[’REMOTE_ADDR’]),
Line 69: ‘remote_addr’ => empty($s[’REMOTE_ADDR’]) ? ‘’ : ip2long($s[’REMOTE_ADDR’]),
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Log\sql\log_setup\mysql4-install-0.7.0.php (1 hits)
Line 109: `remote_addr` bigint(20) default NULL,
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Poll\controllers\VoteController.php (1 hits)
Line 49: ->setIpAddress(ip2long($this->getRequest()->getServer(’REMOTE_ADDR’)))
F:\Business\magento-1.3.0\magento\app\code\core\Mage\Rating\Model\Mysql4\Rating\Option.php (2 hits)
Line 94: $data[’remote_ip’] = $action->getRequest()->getServer(’REMOTE_ADDR’);
Line 95: $data[’remote_ip_long’] = ip2long($action->getRequest()->getServer(’REMOTE_ADDR’));
Here is the updated fix as of version 1.3.2.4 as the fix listed originally no longer applied. The following issue occurs on Rackspace Cloud Sites (formerly known as Mosso).
The file needed to be modified is in /app/code/core/Mage/Core/Helper/Http.php
Instead of editing a core file, you should create a new file in the local version. So copy the Http.php file above and put it here (you’ll probably have to create the directories):