<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>雨天阳光 &#187; 访客</title>
	<atom:link href="http://shit.name/tag/%e8%ae%bf%e5%ae%a2/feed/" rel="self" type="application/rss+xml" />
	<link>http://shit.name</link>
	<description>此人之水镜，见之莹然，若披云雾而睹青天也。</description>
	<lastBuildDate>Wed, 31 Dec 2014 06:21:04 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.33</generator>
	<item>
		<title>WordPress无法正确记录访客评论IP解决方法</title>
		<link>http://shit.name/solution-of-recording-ip/</link>
		<comments>http://shit.name/solution-of-recording-ip/#comments</comments>
		<pubDate>Sat, 11 Aug 2012 13:32:15 +0000</pubDate>
		<dc:creator><![CDATA[Oo雨天阳光oO]]></dc:creator>
				<category><![CDATA[互联二亩田]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[访客]]></category>
		<category><![CDATA[评论]]></category>

		<guid isPermaLink="false">http://shit.name/?p=156</guid>
		<description><![CDATA[这个博客架设在Xehost的达拉斯VPS上，不过细心的童鞋应该发觉访问速度比美国的VPS快很多，实际Ping值 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-157" title="message" src="http://shit.name/wp-content/uploads/2012/08/message.jpg" alt="" width="614" height="120" /><br />
这个博客架设在<a title="Xehost" href="http://shit.name/go/xehost/" target="_blank">Xehost</a>的达拉斯VPS上，不过细心的童鞋应该发觉访问速度比美国的VPS快很多，实际Ping值也在100以下。其实这都归功于CDN，目前在用<a title="incapsula" href="http://shit.name/go/incapsula/" target="_blank">incapsula</a>的免费款（每月50G流量对于一般BLOG都够用），而且幸运地被分配到了日本节点，所以访问速度比较不错。<br />
速度是上去了，不过随之而来的问题就是无法获得访客评论时的真正IP——显示的都是那个日本节点的IP地址。经过一番搜索后，找到很多方法，实际测试下来有两种方法是比较靠谱的。<span id="more-156"></span></p>
<div class='newcode'><h2>第一种方法：</h2><div class='newcontent'>在wp-config.php开头加入以下代码：（把wp-config.php中的代码全部看了遍，并无关于获取IP地址的其他代码，所以我加在了最后，实际效果和在开头一样）</p>
<pre class="brush: php; title: ; notranslate">/* 获取评论的真实IP */
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0];}</pre>
<p></div></div>
<div class='newcode'><h2>第二种方法：</h2><div class='newcontent'>打开wp-includes/comment.php，找到wp_new_comment函数，这个函数是将一个新评论入库。<br />
把其中
<pre class="brush: php; title: ; notranslate">$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', &quot;,$_SERVER['REMOTE_ADDR'] );</pre>
<p>修改为
<pre class="brush: php; title: ; notranslate">$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', &quot;,$_SERVER['HTTP_X_FORWARDED_FOR'] );</pre>
<p>另外将
<pre class="brush: php; title: ; notranslate">$_SERVER['REMOTE_ADDR']</pre>
<p>替换为
<pre class="brush: php; title: ; notranslate">$_SERVER[&quot;HTTP_X_FORWARDED_FOR&quot;]</pre>
<p>这样就OK了</div></div>
<blockquote><p>做下注解：<br />
$_SERVER['REMOTE_ADDR'] #正在浏览当前页面用户的 IP 地址。<br />
$_SERVER["HTTP_X_FORWARDED_FOR"] #透过代理服务器取得客户端的真实 IP 地址</p></blockquote>
<p>两种方法我测试下来，实际上是有区别的，主要在于系统因为评论给博主自动发的通知邮件，如图中红框所示：<br />
<img class="alignnone size-full wp-image-158" title="recording_ip_screenshot" src="http://shit.name/wp-content/uploads/2012/08/recording_ip_screenshot.jpg" alt="" width="560" height="616" /><br />
上面是用方法一被评论后收到的邮件——评论者IP和其主机名一致；下面是用方法二后得到的——评论者IP有两个而且其主机名没有获取到。</p>
<blockquote><p>从上得出的结论就是：<br />
<span style="color: #993300;"><strong>强烈建议使用第一种方法——简洁、方便、完美！</strong></span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://shit.name/solution-of-recording-ip/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
