An example of patching cloudflare running Magento server
* Files needed
app/code/local/Fourthmedia/Http/etc/config.xml
app/code/local/Fourthmedia/Http/Helper/Cloudflarehttp.php
app/etc/modules/Fourthmedia_Http.xml
* Example source code
// app/code/local/Fourthmedia/Http/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Fourthmedia_Http>
<version>0.1.0</version>
</Fourthmedia_Http>
</modules>
<global>
<helpers>
<core>
<rewrite>
<http>Fourthmedia_Http_Helper_Cloudflarehttp</http>
</rewrite>
</core>
</helpers>
</global>
</config>
// app/code/local/Fourthmedia/Http/Helper/Cloudflarehttp.php
<?php
class Fourthmedia_Http_Helper_Cloudflarehttp extends Mage_Core_Helper_Http
{
public function getRemoteAddr($ipToLong = false)
{
if (is_null($this->_remoteAddr)) {
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$this->_remoteAddr = $_SERVER["HTTP_CF_CONNECTING_IP"];
$this->_remoteAddr = $ipToLong ? inet_pton($this->_remoteAddr) : $this->_remoteAddr;
} else {
$this->_remoteAddr = parent::getRemoteAddr(false);
}
}
return $this->_remoteAddr;
}
}
// app/etc/modules/Fourthmedia_Http.xml
<?xml version="1.0"?>
<config>
<modules>
<Fourthmedia_Http>
<active>true</active>
<codePool>local</codePool>
</Fourthmedia_Http>
</modules>
</config>
* Files needed
app/code/local/Fourthmedia/Http/etc/config.xml
app/code/local/Fourthmedia/Http/Helper/Cloudflarehttp.php
app/etc/modules/Fourthmedia_Http.xml
* Example source code
// app/code/local/Fourthmedia/Http/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Fourthmedia_Http>
<version>0.1.0</version>
</Fourthmedia_Http>
</modules>
<global>
<helpers>
<core>
<rewrite>
<http>Fourthmedia_Http_Helper_Cloudflarehttp</http>
</rewrite>
</core>
</helpers>
</global>
</config>
// app/code/local/Fourthmedia/Http/Helper/Cloudflarehttp.php
<?php
class Fourthmedia_Http_Helper_Cloudflarehttp extends Mage_Core_Helper_Http
{
public function getRemoteAddr($ipToLong = false)
{
if (is_null($this->_remoteAddr)) {
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$this->_remoteAddr = $_SERVER["HTTP_CF_CONNECTING_IP"];
$this->_remoteAddr = $ipToLong ? inet_pton($this->_remoteAddr) : $this->_remoteAddr;
} else {
$this->_remoteAddr = parent::getRemoteAddr(false);
}
}
return $this->_remoteAddr;
}
}
// app/etc/modules/Fourthmedia_Http.xml
<?xml version="1.0"?>
<config>
<modules>
<Fourthmedia_Http>
<active>true</active>
<codePool>local</codePool>
</Fourthmedia_Http>
</modules>
</config>
Comments
Post a Comment