<?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>diablo3 &#187; 登录</title>
	<atom:link href="http://www.wpall.com/p/tag/%e7%99%bb%e5%bd%95/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wpall.com</link>
	<description>What's diablo 3?</description>
	<lastBuildDate>Mon, 01 Jun 2009 23:16:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>wordpress代码分析 &#8212;- wp_safe_redirect</title>
		<link>http://www.wpall.com/p/51</link>
		<comments>http://www.wpall.com/p/51#comments</comments>
		<pubDate>Tue, 08 Apr 2008 06:57:39 +0000</pubDate>
		<dc:creator>presser</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[登录]]></category>
		<category><![CDATA[代码分析]]></category>

		<guid isPermaLink="false">http://www.wpall.com/?p=51</guid>
		<description><![CDATA[wordpress代码分析 ---- wp_safe_redirect。wordpress提供了一个跳转方法wp_safe_redirect，避免登录url被修改，登录成功后跳转到有害的第三方站点。如下：
PLAIN TEXT
PHP:




/**


 * wp_safe_redirect() - Performs a safe (local) redirect, using wp_redirect()


 *


 * Checks whether the $location is using an allowed host, if it has an absolute


 * path. A plugin can therefore set or remove allowed host(s) to or from the list.


 *


 * If the host is not allowed, then [...]]]></description>
			<content:encoded><![CDATA[<p>wordpress<a href="index.php?tag=%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90">代码分析</a> ---- wp_safe_redirect。wordpress提供了一个跳转方法wp_safe_redirect，避免登录url被修改，登录成功后跳转到有害的第三方站点。如下：</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/**</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * wp_safe_redirect() - Performs a safe (local) redirect, using wp_redirect()</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> *</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * Checks whether the $location is using an allowed host, if it has an absolute</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * path. A plugin can therefore set or remove allowed host(s) to or from the list.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> *</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * If the host is not allowed, then the redirect is to wp-admin on the siteurl</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * instead. This prevents malicious redirects which redirect to another host, but</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * only used in a few places.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> *</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * @since 2.3</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> *&nbsp; &nbsp; WordPress host string and $location host string.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> *</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * @return void Does not return anything</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> **/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> wp_safe_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$location</span>, <span style="color:#0000FF;">$status</span> = <span style="color:#CC66CC;color:#800000;">302</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// Need to look at the URL the way it will end up in wp_redirect()</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$location</span> = wp_sanitize_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$location</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#000066;">substr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$location</span>, <span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#CC66CC;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#FF0000;">'//'</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$location</span> = <span style="color:#FF0000;">'http:'</span> . <span style="color:#0000FF;">$location</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$lp</span>&nbsp; = <span style="color:#000066;">parse_url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$location</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$wpp</span> = <span style="color:#000066;">parse_url</span><span style="color:#006600; font-weight:bold;">&#40;</span>get_option<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'home'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$allowed_hosts</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000066;">array</span><span style="color:#006600; font-weight:bold;">&#41;</span> apply_filters<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'allowed_redirect_hosts'</span>, <span style="color:#000066;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$wpp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000066;">isset</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$lp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF;">$lp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span> : <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#000066;">isset</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$lp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#006600; font-weight:bold;">&#40;</span> !<span style="color:#000066;">in_array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$lp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF;">$allowed_hosts</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#0000FF;">$lp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span> != <span style="color:#000066;">strtolower</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$wpp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'host'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$location</span> = get_option<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'siteurl'</span><span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">'/wp-admin/'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; wp_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$location</span>, <span style="color:#0000FF;">$status</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>如果需要跳转到可信的第三方站点，可以修改filter hook  ---- <strong>allowed_redirect_hosts</strong>，把可信任的第三方站点加入列表，这样也就达到了扩展wordpress的目的。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpall.com/p/51/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.944 seconds -->
