<?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>淡水河边的博客</title>
	<atom:link href="http://www.tsingfeng.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.tsingfeng.com</link>
	<description>生活在继续，希望就不灭，一切的美好也会在痛苦中茁壮成长</description>
	<lastBuildDate>Fri, 20 Aug 2010 01:27:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Access Control Library for Codeigniter</title>
		<link>http://www.tsingfeng.com/?p=561</link>
		<comments>http://www.tsingfeng.com/?p=561#comments</comments>
		<pubDate>Thu, 19 Aug 2010 12:21:54 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[acl]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=561</guid>
		<description><![CDATA[先检讨。比较浮躁，先前帖的Codeigniter ACL library 有较大的bug。配置和使用方法也没有说太多。今天正好用到，调试了一下。重新发布。嗯，这个也是淡水在ci在官网论坛上挖到的。还有个autoacl的，也是基于这个修改的。不过淡水觉得太耦合了，而且繁琐了。还是没有采用。 先来library： &#60;?php if (!defined('BASEPATH')) exit('No direct script access allowed');/**&#160;* MX_ACL - Access Control Library PHP5&#160;* &#160;* Notes:&#160;* $config['cache_path'] must be set&#160;*&#160;* Install this file as application/libraries/MX_ACL.php&#160;* &#160;* @copyright &#160; &#160;Copyright (c) Wiredesignz &#38; Maxximus 2009-11-03&#160;* @version &#160; &#160; 1.1&#160;* &#160;* Permission is hereby granted, free of charge, to any person obtaining [...]]]></description>
			<content:encoded><![CDATA[<p>先检讨。比较浮躁，先前帖的<a href="http://www.tsingfeng.com/?p=496">Codeigniter ACL library</a> 有较大的bug。配置和使用方法也没有说太多。今天正好用到，调试了一下。重新发布。嗯，这个也是淡水在ci在官网论坛上挖到的。还有个autoacl的，也是基于这个修改的。不过淡水觉得太耦合了，而且繁琐了。还是没有采用。</p>
<p>先来library：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">defined</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">BASEPATH</span><span style="color: #8b0000;">'</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Green;">exit</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">No direct script access allowed</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: #ffa500;">/**<br />&nbsp;* MX_ACL - Access Control Library PHP5<br />&nbsp;* <br />&nbsp;* Notes:<br />&nbsp;* $config['cache_path'] must be set<br />&nbsp;*<br />&nbsp;* Install this file as application/libraries/MX_ACL.php<br />&nbsp;* <br />&nbsp;*</span><span style="color: Blue;"> @copyright </span><span style="color: #ffa500;">&nbsp; &nbsp;Copyright (c) Wiredesignz &amp; Maxximus 2009-11-03<br />&nbsp;*</span><span style="color: Blue;"> @version </span><span style="color: #ffa500;">&nbsp; &nbsp; 1.1<br />&nbsp;* <br />&nbsp;* Permission is hereby granted, free of charge, to any person obtaining a copy<br />&nbsp;* of this software and associated documentation files (the &quot;Software&quot;), to deal<br />&nbsp;* in the Software without restriction, including without limitation the rights<br />&nbsp;* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />&nbsp;* copies of the Software, and to permit persons to whom the Software is<br />&nbsp;* furnished to do so, subject to the following conditions:<br />&nbsp;* <br />&nbsp;* The above copyright notice and this permission notice shall be included in<br />&nbsp;* all copies or substantial portions of the Software.<br />&nbsp;* <br />&nbsp;* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />&nbsp;* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />&nbsp;* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />&nbsp;* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />&nbsp;* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />&nbsp;* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />&nbsp;* THE SOFTWARE.<br />&nbsp;*/</span><span style="color: Gray;"><br /></span><span style="color: Green;">class</span><span style="color: Gray;"> </span><span style="color: Blue;">MX_ACL</span><span style="color: Gray;"><br /></span><span style="color: Olive;">{</span><span style="color: Gray;">&nbsp; &nbsp; <br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">private</span><span style="color: Gray;"> </span><span style="color: #00008b;">$_config</span><span style="color: Gray;">, </span><span style="color: #00008b;">$_cache_path</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">public</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">__construct</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">load</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">helper</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">url</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">load</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">library</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">session</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">load</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">config</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">mx_acl</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">TRUE</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">config</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">item</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">mx_acl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">#$this-&gt;_cache_path = $this-&gt;config-&gt;item('cache_path');</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_cache_path</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">config</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">item</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">cache_path</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">mx_acl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* previous flashdata is available to views */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">load</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">vars</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_var</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">flashdata</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_var</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* run the access control check now */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">check_uri</span><span style="color: #8b0000;">'</span><span style="color: Olive;">])</span><span style="color: Gray;"> </span><span style="color: Green;">AND</span><span style="color: Gray;"> </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">check_uri</span><span style="color: Olive;">()</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #ffa500;">/**<br />&nbsp;&nbsp; &nbsp; * Check the current uri and user privileges against the cached ACL array<br />&nbsp;&nbsp; &nbsp; * Redirect if access is denied<br />&nbsp;&nbsp; &nbsp; * <br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @return </span><span style="color: #ffa500;">void<br />&nbsp;&nbsp; &nbsp; */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">public</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">check_uri</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Load the cached access control list or show error */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">is_file</span><span style="color: Olive;">(</span><span style="color: #00008b;">$cached_acl</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_cache_path</span><span style="color: Gray;">.</span><span style="color: #8b0000;">'</span><span style="color: Red;">mx_acl</span><span style="color: #8b0000;">'</span><span style="color: Gray;">.</span><span style="color: Blue;">EXT</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Green;">OR</span><span style="color: Gray;"> </span><span style="color: Blue;">show_error</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Olive;">])</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$acl</span><span style="color: Gray;"> = </span><span style="color: Green;">include</span><span style="color: Gray;"> </span><span style="color: #00008b;">$cached_acl</span><span style="color: Gray;">;<br />&nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Match current url to access list */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">#if (is_array($acl) AND $acl = $this-&gt;match_uri($this-&gt;current_uri(), $acl)) {</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">is_array</span><span style="color: Olive;">(</span><span style="color: #00008b;">$acl</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Green;">AND</span><span style="color: Gray;"> </span><span style="color: #00008b;">$acl</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">match_uri</span><span style="color: Olive;">(</span><span style="color: Blue;">strtolower</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">current_uri</span><span style="color: Olive;">())</span><span style="color: Gray;">, </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Check session group against access level group */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$allow_access</span><span style="color: Gray;"> = </span><span style="color: Olive;">(</span><span style="color: Blue;">bool</span><span style="color: Olive;">)(</span><span style="color: Blue;">in_array</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">userdata</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">session_var</span><span style="color: #8b0000;">'</span><span style="color: Olive;">])</span><span style="color: Gray;">, </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">allowed</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">/* Additional check to allow IP addresses in range */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$allow_access</span><span style="color: Gray;"> </span><span style="color: Green;">AND</span><span style="color: Gray;"> </span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">ipl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]))</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">is_array</span><span style="color: Olive;">(</span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">ipl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]))</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$allow_access</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">check_ip</span><span style="color: Olive;">(</span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">ipl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">])</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$allow_access</span><span style="color: Gray;"> == </span><span style="color: Green;">FALSE</span><span style="color: Olive;">)</span><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Set a return url into the session */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">set_userdata</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">return_url</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">uri</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">uri_string</span><span style="color: Olive;">())</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* set the error message... */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$error_msg</span><span style="color: Gray;"> = </span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]))</span><span style="color: Gray;"> ? </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> : </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* set a flash message... */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">set_flashdata</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">_config</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_var</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: #00008b;">$error_msg</span><span style="color: Olive;">)</span><span style="color: Gray;">;&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* redirect to absolute url */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">die</span><span style="color: Olive;">(</span><span style="color: Blue;">header</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">Location: </span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">.</span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_uri</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: Green;">TRUE</span><span style="color: Gray;">, </span><span style="color: Maroon;">302</span><span style="color: Olive;">))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #ffa500;">/**<br />&nbsp;&nbsp; &nbsp; * Return the access control profile for a given url<br />&nbsp;&nbsp; &nbsp; * <br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @return </span><span style="color: #ffa500;">string<br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @param </span><span style="color: #ffa500;">string $current_uri<br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @param </span><span style="color: #ffa500;">array&nbsp; $acl<br />&nbsp;&nbsp; &nbsp; */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">private</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">match_uri</span><span style="color: Olive;">(</span><span style="color: #00008b;">$current_uri</span><span style="color: Gray;">, </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">array_key_exists</span><span style="color: Olive;">(</span><span style="color: #00008b;">$current_uri</span><span style="color: Gray;">, </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">[</span><span style="color: #00008b;">$current_uri</span><span style="color: Olive;">]</span><span style="color: Gray;">;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$pos</span><span style="color: Gray;"> = </span><span style="color: Blue;">strripos</span><span style="color: Olive;">(</span><span style="color: #00008b;">$current_uri</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">/</span><span style="color: #8b0000;">'</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">match_uri</span><span style="color: Olive;">(</span><span style="color: Blue;">substr</span><span style="color: Olive;">(</span><span style="color: #00008b;">$current_uri</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Gray;">, </span><span style="color: #00008b;">$pos</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: #00008b;">$acl</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #ffa500;">/**<br />&nbsp;&nbsp; &nbsp; * Returns the current uri string from segments<br />&nbsp;&nbsp; &nbsp; * <br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @return </span><span style="color: #ffa500;">string<br />&nbsp;&nbsp; &nbsp; */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">private</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">current_uri</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">implode</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">/</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">uri</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">rsegments</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #ffa500;">/** <br />&nbsp;&nbsp; &nbsp; * Checks the remote IP address against the specified $ipl array<br />&nbsp;&nbsp; &nbsp; * <br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @return </span><span style="color: #ffa500;">bool<br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @param </span><span style="color: #ffa500;">array $ipl<br />&nbsp;&nbsp; &nbsp; *</span><span style="color: Blue;"> @param </span><span style="color: #ffa500;">string $remote_ip[optional]<br />&nbsp;&nbsp; &nbsp; */</span><span style="color: Gray;">&nbsp; &nbsp; <br />&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">private</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">check_ip</span><span style="color: Olive;">(</span><span style="color: #00008b;">$ipl</span><span style="color: Gray;">, </span><span style="color: #00008b;">$remote_ip</span><span style="color: Gray;"> = </span><span style="color: Green;">NULL</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Convert ip address into a double (for lousy OSes)*/</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$remote_ip</span><span style="color: Gray;"> = </span><span style="color: Blue;">floatval</span><span style="color: Olive;">(</span><span style="color: Blue;">ip2long</span><span style="color: Olive;">((</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">userdata</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">ip_address</span><span style="color: #8b0000;">'</span><span style="color: Olive;">))))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Loop through the ip list array */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">foreach</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$ipl</span><span style="color: Gray;"> </span><span style="color: Green;">as</span><span style="color: Gray;"> </span><span style="color: #00008b;">$allowed_ip</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Replace '*' (for IP ranges) with a suitable range number */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$min</span><span style="color: Gray;"> = </span><span style="color: Blue;">str_replace</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">*</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">0</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #00008b;">$allowed_ip</span><span style="color: Olive;">)</span><span style="color: Gray;">;&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #00008b;">$max</span><span style="color: Gray;"> = </span><span style="color: Blue;">str_replace</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">*</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">255</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #00008b;">$allowed_ip</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">/* Check for a match */</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">((</span><span style="color: #00008b;">$remote_ip</span><span style="color: Gray;"> &gt;= </span><span style="color: Blue;">floatval</span><span style="color: Olive;">(</span><span style="color: Blue;">ip2long</span><span style="color: Olive;">(</span><span style="color: #00008b;">$min</span><span style="color: Olive;">)))</span><span style="color: Gray;"> </span><span style="color: Green;">AND</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$remote_ip</span><span style="color: Gray;"> &lt;= </span><span style="color: Blue;">floatval</span><span style="color: Olive;">(</span><span style="color: Blue;">ip2long</span><span style="color: Olive;">(</span><span style="color: #00008b;">$max</span><span style="color: Olive;">))))</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Green;">TRUE</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">public</span><span style="color: Gray;"> </span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">__get</span><span style="color: Olive;">(</span><span style="color: #00008b;">$var</span><span style="color: Olive;">)</span><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">static</span><span style="color: Gray;"> </span><span style="color: #00008b;">$CI</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">is_object</span><span style="color: Olive;">(</span><span style="color: #00008b;">$CI</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Green;">OR</span><span style="color: Gray;"> </span><span style="color: #00008b;">$CI</span><span style="color: Gray;"> = </span><span style="color: Blue;">get_instance</span><span style="color: Olive;">()</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: #00008b;">$CI</span><span style="color: Gray;">-&gt;</span><span style="color: #00008b;">$var</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: #ffa500;">/* End of file MX_ACL.php */</span><span style="color: Gray;"><br /></span><span style="color: #ffa500;">/* Location: ./application/libraries/MX_ACL.php */</span></div></div>
<p>再来配置文件：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">defined</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">BASEPATH</span><span style="color: #8b0000;">'</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Green;">exit</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">No direct script access allowed</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: #ffa500;">/**<br />&nbsp;* MX_Acl configuration<br />&nbsp;*<br />&nbsp;* Save this file as application/config/mx_acl.php<br />&nbsp;*/</span><span style="color: Gray;"><br /></span><span style="color: #00008b;">$config</span><span style="color: Gray;"> = </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">check_uri</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; =&gt; </span><span style="color: Green;">TRUE</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_var</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">error</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">You don</span><span style="color: Navy;">\'</span><span style="color: Red;">t have sufficient access rights to view this page!</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">session_var</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">role_id</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">cache_path</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp;=&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">application/acl/</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,<br /></span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<p>具体的acl，没有写入到db，直接放到上面的cache_path中的：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">defined</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">BASEPATH</span><span style="color: #8b0000;">'</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Green;">exit</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">No direct script access allowed</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: #ffa500;">/**<br />&nbsp;* This is the cached access control list <br />&nbsp;* <br />&nbsp;* save this file as {cache_path}/mx_acl.php<br />&nbsp;*/</span><span style="color: Gray;"><br /></span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">setting/update</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">// the &quot;module/controller/method&quot; to protect</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">allowed</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Maroon;">1</span><span style="color: Olive;">)</span><span style="color: Gray;">,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// the allowed user role_id array (eg.$this-&gt;session-&gt;set_userdata('role_id','1'))</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">ipl</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">127.0.0.1</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// the allowed IP range array or FALSE(allowed all ip)</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_uri</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; =&gt; </span><span style="color: Blue;">site_url</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">secure/setting</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,&nbsp; </span><span style="color: #ffa500;">// the url to redirect to on failure</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">You do not have permission to update this page!</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">)</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">page/update</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">allowed</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Maroon;">1</span><span style="color: Gray;">, </span><span style="color: Maroon;">2</span><span style="color: Gray;">, </span><span style="color: Maroon;">3</span><span style="color: Olive;">)</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">ipl</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">127.0.0.0</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">127.0.0.*</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_uri</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; =&gt; </span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$_SERVER</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">HTTP_REFERER</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]))</span><span style="color: Gray;"> ? </span><span style="color: #00008b;">$_SERVER</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">HTTP_REFERER</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> : </span><span style="color: Blue;">site_url</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">secure/page</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">error_msg</span><span style="color: #8b0000;">'</span><span style="color: Gray;">&nbsp; =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">You do not have permission to update this page!</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">)</span><span style="color: Gray;">,<br /></span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<p>staticpage的内容，处理未授权显示：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"><br /></span><span style="color: Green;">class</span><span style="color: Gray;"> </span><span style="color: Blue;">Staticpage</span><span style="color: Gray;"> </span><span style="color: Green;">extends</span><span style="color: Gray;"> </span><span style="color: Blue;">Controller</span><span style="color: Gray;"><br /></span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">error_auth</span><span style="color: Olive;">()</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">show_error</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">flashdata</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">error</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span><span style="color: Maroon;">203</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Olive;">}</span></div></div>
<p>登录时给出相应的角色：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">session</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">set_userdata</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">role_id</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">1</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<p>基本就是这样了。role_id使用了ci自带的session；errror用的也是的session的flashdata。嗯，就是这样，没有了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=561</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>li水平居中css实现</title>
		<link>http://www.tsingfeng.com/?p=557</link>
		<comments>http://www.tsingfeng.com/?p=557#comments</comments>
		<pubDate>Thu, 05 Aug 2010 12:26:42 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=557</guid>
		<description><![CDATA[其实这个是凑数来的。只是好久没动博客了，实在是说不过去了，丫的太懒了。其实是淡水没有时间（好假的借口）。 闲话不多说了。现在一般都是用li做菜单了，淡水也就从了。li的float:left,可以了变成横向的菜单了。但是它们怎么跑到区域里居中显示呢（一般是页脚的链接是居中的）？li的display:inline;就可以了，float：left都不要了，自己跑一行去了。 #main_footer{ list-style:none; text-align:center; } #main_footer li{ display:inline; } &#60;ul id=&#8221;main_footer&#8221;&#62; &#60;li&#62;&#60;a href=&#8221;#&#8221;&#62;公司介绍&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#8221;#&#8221;&#62;我们的创新&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#8221;#&#8221;&#62;工作理念&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#8221;#&#8221;&#62;价值观&#60;/a&#62;&#60;/li&#62; &#60;li&#62;&#60;a href=&#8221;#&#8221;&#62;联系我们&#60;/a&#62;&#60;/li&#62; &#60;/ul&#62; 其实淡水还是在用table布局，为啥，方便啊。不过也少了:) 哎，div啊。。。]]></description>
			<content:encoded><![CDATA[<p>其实这个是凑数来的。只是好久没动博客了，实在是说不过去了，丫的太懒了。其实是淡水没有时间（好假的借口）。</p>
<p>闲话不多说了。现在一般都是用li做菜单了，淡水也就从了。li的float:left,可以了变成横向的菜单了。但是它们怎么跑到区域里居中显示呢（一般是页脚的链接是居中的）？li的display:inline;就可以了，float：left都不要了，自己跑一行去了。</p>
<p>#main_footer{<br />
list-style:none;<br />
text-align:center;<br />
}<br />
#main_footer li{<br />
display:inline;<br />
}</p>
<p>&lt;ul id=&#8221;main_footer&#8221;&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;公司介绍&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;我们的创新&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;工作理念&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;价值观&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;联系我们&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;</p>
<p>其实淡水还是在用table布局，为啥，方便啊。不过也少了:)</p>
<p>哎，div啊。。。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=557</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShangHai</title>
		<link>http://www.tsingfeng.com/?p=554</link>
		<comments>http://www.tsingfeng.com/?p=554#comments</comments>
		<pubDate>Thu, 29 Jul 2010 01:54:30 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=554</guid>
		<description><![CDATA[嗯，新环境……]]></description>
			<content:encoded><![CDATA[<p>嗯，新环境……</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=554</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mysql查询今天、昨天、7天、近30天、本月、上一月 数据</title>
		<link>http://www.tsingfeng.com/?p=537</link>
		<comments>http://www.tsingfeng.com/?p=537#comments</comments>
		<pubDate>Sat, 26 Jun 2010 11:24:40 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=537</guid>
		<description><![CDATA[今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) &#8211; TO_DAYS( 时间字段名) &#60;= 1 7天 SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) &#60;= date(时间字段名) 近30天 SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) &#60;= date(时间字段名) 本月 SELECT * FROM 表名 WHERE DATE_FORMAT( [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">
<div id="_mcePaste">今天</div>
<div id="_mcePaste">select * from 表名 where to_days(时间字段名) = to_days(now());</div>
<div id="_mcePaste">昨天</div>
<div id="_mcePaste">SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) &#8211; TO_DAYS( 时间字段名) &lt;= 1</div>
<div id="_mcePaste">7天</div>
<div id="_mcePaste">SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(时间字段名)</div>
<div id="_mcePaste">近30天</div>
<div id="_mcePaste">SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) &lt;= date(时间字段名)</div>
<div id="_mcePaste">本月</div>
<div id="_mcePaste">SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, &#8216;%Y%m&#8217; ) = DATE_FORMAT( CURDATE( ) , &#8216;%Y%m&#8217; )</div>
<div id="_mcePaste">上一月</div>
<div id="_mcePaste">SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , &#8216;%Y%m&#8217; ) , date_format( 时间字段名, &#8216;%Y%m&#8217; ) ) =1</div>
<div></div>
<div>来源：http://blog.163.com/dreamman_yx/blog/static/26526894201053115622827/</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=537</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install ‘xdebug’ PHP extension for XAMPP on Ubuntu10.04</title>
		<link>http://www.tsingfeng.com/?p=523</link>
		<comments>http://www.tsingfeng.com/?p=523#comments</comments>
		<pubDate>Wed, 23 Jun 2010 08:38:09 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[xampp]]></category>
		<category><![CDATA[Xdebug]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=523</guid>
		<description><![CDATA[First you have to install XAMPP development package (http://www.apachefriends.org/en/xampp-linux.html) for your XAMPP installation. This package provides the necessary source files needed to compile the extra stuff Download &#8216;xdebug&#8217; source from http://www.xdebug.com/ , uncompress it in a suitable directory, cd to that directory. Now run phpize [bruce@bruce-laptop xdebug-2.1.0RC1]$ /opt/lampp/bin/phpize if had errors: Cannot find autoconf. Please [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>
<p class="cjk" style="margin-bottom: 0cm;"><span style="font-family: Times New Roman,serif;"><span lang="en-US"><span style="font-family: Gentium Basic;">First you have to </span><span style="color: #ff3333;"><span style="font-family: Gentium Basic;"><strong>install XAMPP development package</strong></span></span><span style="font-family: Gentium Basic;"><br />
(http://www.apachefriends.org/en/xampp-linux.html) for your XAMPP<br />
installation. This package provides the necessary source files<br />
needed to compile the extra stuff </span></span></span></p>
</li>
</ul>
<ul>
<li>
<p class="cjk" style="margin-bottom: 0cm;"><span style="font-family: Gentium Basic;"><span lang="en-US">Download &#8216;xdebug&#8217; source from http://www.xdebug.com/ , uncompress it in a<br />
suitable directory, cd to that directory. </span></span></p>
</li>
</ul>
<ul>
<li>
<p class="cjk"><span style="font-family: Gentium Basic;"><span lang="en-US">Now run phpize</span></span></p>
</li>
</ul>
<p class="cjk" style="margin-left: 1.27cm;"><span style="font-family: Times New Roman,serif;"><span lang="en-US"><span style="color: #006600;"><span style="font-family: Gentium Basic;"><strong><span style="background: #cccccc;">[</span></strong></span></span><span style="font-family: Gentium Basic;"><span style="background: #cccccc;">bruce@bruce-laptop xdebug-</span></span><span style="color: #800000;"><span style="font-family: Gentium Basic;"><span style="background: #cccccc;">2</span></span></span><span style="font-family: Gentium Basic;"><span style="background: #cccccc;">.1.0RC1</span></span><span style="color: #006600;"><span style="font-family: Gentium Basic;"><strong><span style="background: #cccccc;">]</span></strong></span></span><span style="font-family: Gentium Basic;"><span style="background: #cccccc;">$ /opt/lampp/bin/phpize</span></span></span></span></p>
<p class="cjk" style="margin-left: 2.54cm;"><span style="font-family: Gentium Basic;"><span lang="en-US"><em>if had errors:<span style="background: #b3b3b3;"><br />
Cannot find autoconf. Please check your autoconf installation and the<br />
$PHP_AUTOCONF environment variable is set correctly and then rerun<br />
this script. </span></em></span></span></p>
<p class="cjk" style="margin-left: 2.54cm;"><span style="font-family: Times New Roman,serif;"><span lang="en-US"><span style="font-family: Gentium Basic;"><em>try determining if ‘autoconf’ is installed ,by just running<br />
</em></span><span style="font-family: Gentium Basic;"><em><span style="background: #cccccc;">$autoconf</span></em></span></span></span></p>
<p class="cjk" style="margin-left: 2.54cm;"><span style="font-family: Gentium Basic;"><span lang="en-US"><em><span style="background: transparent;">if it’s not there then you will need to install the tool first, you can do it by,</span></em></span></span></p>
<p class="cjk" style="margin-left: 2.54cm;"><span style="font-family: Gentium Basic;"><span lang="en-US"><em><span style="background: #cccccc;">sudo apt-get install autoconf</span></em></span></span></p>
<ul>
<li>
<p class="cjk" style="margin-bottom: 0cm;"><span style="font-family: Gentium Basic;"><span lang="en-US">Configure the extension </span></span></p>
</li>
</ul>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm;"><span style="font-family: Times New Roman,serif;"><span lang="en-US"><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><strong><span style="background: #cccccc;">[</span></strong></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><span style="font-weight: normal;"><span style="background: #cccccc;">bruce@bruce-laptop xdebug-2.1.0RC1</span></span></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><strong><span style="background: #cccccc;">]</span></strong></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><span style="font-weight: normal;"><span style="background: #cccccc;">$ ./configure &#8211;enable-xdebug &#8211;with-php-config=/opt/lampp/bin/php-config </span></span></span></span></span></span></p>
<ul>
<li>
<p class="cjk" style="margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US">Run &#8216;make&#8217; to get the compiled xdebug.so </span></span></p>
</li>
</ul>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm;"><span style="font-family: Times New Roman,serif;"><span lang="en-US"><span style="background: #cccccc;"><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><strong>[</strong></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><span style="font-weight: normal;">bruce@bruce-laptop xdebug-2.1.0RC1</span></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><strong>]</strong></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><span style="font-weight: normal;">$ make</span></span></span></span></span></span></p>
<ul>
<li>
<p class="cjk" style="margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US">Copy the xdebug.so file to PHP&#8217;s extensions directory (you may need root privileges for<br />
this) </span></span></p>
<p class="cjk" style="margin-bottom: 0cm;"><span style="font-family: Times New Roman,serif;"><span lang="en-US"><span style="background: #cccccc;"><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><strong>[</strong></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><span style="font-weight: normal;">bruce@bruce-laptop xdebug-2.1.0RC1</span></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><strong>]</strong></span></span><span style="font-family: Gentium Basic;"><span style="font-style: normal;"><span style="font-weight: normal;">$ sudo cp modules/xdebug.so /opt/lampp/lib/php/extensions </span></span></span></span></span></span></p>
</li>
<li>
<p class="cjk" style="margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US">After that edit php.ini file and add</span></span></p>
</li>
</ul>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">;xDebug Configuration starts<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">zend_extension = /opt/lampp/lib/php/extensions/xdebug.so<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">xdebug.profiler_output_dir = &#8220;/tmp/xdebug/&#8221;<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">xdebug.profiler_enable = On<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">xdebug.remote_enable=On<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">xdebug.remote_host=&#8221;localhost&#8221;<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">xdebug.remote_port=9000<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">xdebug.remote_handler=&#8221;dbgp&#8221;<br />
</span></span></span></p>
<p class="cjk" style="margin-left: 1.27cm; margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;">;xDebug Configuration ends</span></span></span></p>
<ul>
<li>
<p class="cjk" style="margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US">Lastly restart XAMPP and check phpinfo for Xdebug extension </span></span></p>
<p class="cjk" style="margin-bottom: 0cm; font-style: normal; font-weight: normal;"><span style="font-family: Gentium Basic;"><span lang="en-US"><span style="background: #cccccc;"><strong>[</strong>bruce@bruce-laptop xdebug-2.1.0RC1<strong>]</strong>$ sudo /opt/lampp/lampp restart </span></span></span></p>
</li>
</ul>
<p>嗯，openoffice用不太习惯，被d版的ms office惯坏了:(</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=523</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于ci和zend framework的一些牢骚</title>
		<link>http://www.tsingfeng.com/?p=533</link>
		<comments>http://www.tsingfeng.com/?p=533#comments</comments>
		<pubDate>Fri, 11 Jun 2010 02:32:57 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=533</guid>
		<description><![CDATA[首先说明，这是淡水的牢骚，看不惯不要看。 老华仔歌里唱的应景“总逃不开工作表，做完了又来了，怎样也甩不掉……”。淡水手头的项目还没有完全结束，新的项目又要上马。于是前期就框架选择开大会，开小会。 有.net高手就开始在网上搜索合适框架。结果他得出的结论是Zend Framework，理由：官方。 不推荐Codeigniter是因为，一家小公司做的，后期支持跟不上。而且ci是轻量级的，功能不强。 php本身就是草根出身，如果看公司大小，那么为什么不用.net? ci是轻量级的，但是php能做的，他都能做，没有内置的功能，可以自己加阿？非得一定要和zend framework一样，几乎把所有能想到用到的功能都整合进去变成皇家内裤（类库）？ 窃以为，做大型应用时应用框架快速开发是可取的，但是要考虑到代码的执行效率，和开发的灵活度。 zend framework能做到的， ci扩展一下也能做到，麻烦一点了。但是zend framwork有ci灵活么，ci2天可以掌握，zend framework可以么（太NB的天才不算）。 这些主流框架的评比本身没有太大的意义。框架只是工具，各有其特点（Yii高效；ci上手容易，代码优雅；thinkphp代码全中文注释，文档齐全；qee……），人才是重点。 如果理由是： zend framework是官方出品，支持应该比其他（ci）公司长久。 zend framework是官方出品，使用人数较多，人力资源丰富。 zend framework内置许多类库，扩展类库的时间可以节省不少。 zend framework内置许多类库，规范了代码（尽量使用内置类库）。 还有最具分量的理由：这是高层主管决定的。 这些我可以接受，但是说ci不行，以否定ci来肯定zend framwork，那就有些牵强了。 滔滔不绝的，连绵不断，就是要表明“zend framework是php官方出品，功能强大。ci一家小公司做的，后期支持跟不上。而且ci是轻量级的，功能不强。”。但是，zend framework哪些方面强大，ci又是哪里功能不强，都没有说出个一二三来。 嗯，滔滔不绝但也要言之有物才行吧！]]></description>
			<content:encoded><![CDATA[<p>首先说明，这是淡水的牢骚，看不惯不要看。</p>
<p>老华仔歌里唱的应景“总逃不开工作表，做完了又来了，怎样也甩不掉……”。淡水手头的项目还没有完全结束，新的项目又要上马。于是前期就框架选择开大会，开小会。</p>
<p>有.net高手就开始在网上搜索合适框架。结果他得出的结论是Zend Framework，理由：官方。<br />
不推荐Codeigniter是因为，一家小公司做的，后期支持跟不上。而且ci是轻量级的，功能不强。<br />
php本身就是草根出身，如果看公司大小，那么为什么不用.net?<br />
ci是轻量级的，但是php能做的，他都能做，没有内置的功能，可以自己加阿？非得一定要和zend framework一样，几乎把所有能想到用到的功能都整合进去变成皇家内裤（类库）？<br />
窃以为，做大型应用时应用框架快速开发是可取的，但是要考虑到代码的执行效率，和开发的灵活度。<br />
zend framework能做到的， ci扩展一下也能做到，麻烦一点了。但是zend framwork有ci灵活么，ci2天可以掌握，zend framework可以么（太NB的天才不算）。<br />
这些主流框架的评比本身没有太大的意义。框架只是工具，各有其特点（Yii高效；ci上手容易，代码优雅；thinkphp代码全中文注释，文档齐全；qee……），人才是重点。</p>
<p>如果理由是：<br />
zend framework是官方出品，支持应该比其他（ci）公司长久。<br />
zend framework是官方出品，使用人数较多，人力资源丰富。<br />
zend framework内置许多类库，扩展类库的时间可以节省不少。<br />
zend framework内置许多类库，规范了代码（尽量使用内置类库）。<br />
还有最具分量的理由：这是高层主管决定的。</p>
<p>这些我可以接受，但是说ci不行，以否定ci来肯定zend framwork，那就有些牵强了。</p>
<p>滔滔不绝的，连绵不断，就是要表明“zend framework是php官方出品，功能强大。ci一家小公司做的，后期支持跟不上。而且ci是轻量级的，功能不强。”。但是，zend framework哪些方面强大，ci又是哪里功能不强，都没有说出个一二三来。</p>
<p>嗯，滔滔不绝但也要言之有物才行吧！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=533</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>恢复Ubuntu的默认面板</title>
		<link>http://www.tsingfeng.com/?p=531</link>
		<comments>http://www.tsingfeng.com/?p=531#comments</comments>
		<pubDate>Thu, 10 Jun 2010 00:10:35 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=531</guid>
		<description><![CDATA[如果不小心将ubuntu的面板弄得一团糟，又不想慢慢找回来。有没有什么方法一键恢复默认状态呢？ 答案是：“能恢复是肯定的，但是没有一键！“。 首先重置面板设置 gconftool &#8211;recursive-unset /apps/panel 然后删除面板设置文件。 rm -rf ~/.gconf/apps/panel 再杀掉控制面板的进程使其重启即可！ pkill gnome-panel 此时默认的顶部底部两个面板就已经回来了。 如果悲剧到没有办法进入终端，那么建个文件。往里面写入这三条命令，再保存为.sh文件。给执行权限，运行即可。 真的好用。 from:http://blog.okkey.net/1202.html]]></description>
			<content:encoded><![CDATA[<p>如果不小心将ubuntu的面板弄得一团糟，又不想慢慢找回来。有没有什么方法一键恢复默认状态呢？<br />
答案是：“能恢复是肯定的，但是没有一键！“。</p>
<p>首先重置面板设置</p>
<div>
<div>gconftool &#8211;recursive-unset /apps/panel</div>
</div>
<p>然后删除面板设置文件。</p>
<div>
<div>rm  -rf ~/.gconf/apps/panel</div>
</div>
<p>再杀掉控制面板的进程使其重启即可！</p>
<div>
<div>pkill gnome-panel</div>
</div>
<p>此时默认的顶部底部两个面板就已经回来了。</p>
<p>如果悲剧到没有办法进入终端，那么建个文件。往里面写入这三条命令，再保存为.sh文件。给执行权限，运行即可。</p>
<p>真的好用。</p>
<p>from:http://blog.okkey.net/1202.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=531</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>投入ubuntu，体验中</title>
		<link>http://www.tsingfeng.com/?p=519</link>
		<comments>http://www.tsingfeng.com/?p=519#comments</comments>
		<pubDate>Wed, 09 Jun 2010 02:26:24 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=519</guid>
		<description><![CDATA[嗯，体验还不错。推荐。。。 不过wine下ie6太耗资源了，能跑死机器。 两天了，基本上手 开发用XAMPP+PDT，PDT在linux下比windows下的速度快些，但是边框太粗，难看。 :p]]></description>
			<content:encoded><![CDATA[<p>嗯，体验还不错。推荐。。。<br />
不过wine下ie6太耗资源了，能跑死机器。<br />
两天了，基本上手<br />
开发用XAMPP+PDT，PDT在linux下比windows下的速度快些，但是边框太粗，难看。<br />
:p</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=519</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN小记</title>
		<link>http://www.tsingfeng.com/?p=515</link>
		<comments>http://www.tsingfeng.com/?p=515#comments</comments>
		<pubDate>Fri, 16 Apr 2010 09:30:51 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=515</guid>
		<description><![CDATA[名词解释： 修订版（revision）：可以认为是某个文件在其生命周期内各个保存的快照，每个快照和一个时间区间对应。 版本库（Repository）：存放修订版的数据库 本地工作拷贝（Local working copy）：修订版在本地的副本 版本的检入（Check in）：本地副本提交到服务器的版本库 检出（Check out）：从服务器的版本库中取出修订版成为本地副本 版本号的来源：有两种策略，基于文件的计数和基于仓库的计数，subversion使用后者 标签（Tags）：为版本加一个名字，便于检出 分支（Branches）：修订版打分支，以后可以平行修改，互不干扰 合并（Merging）：将分支的修订版合并为一个新的修订版 锁（Locking）：为修订版枷锁 冲突（Conflict）：并发版本控制时防止修订版混乱的错误机制 创建版本库 创建服务器端版本库 命令行： svnadmin create file_path/repo_name 初始导入（import） 通过命令行导入： svn import -m &#8220;init import&#8221; http://10.0.0.6/svn/teaching/ 该命令可将当前路径下文件导入到版本库中。 检出（checkout） 通过命令行检入： svn co http://10.0.0.6/svn/teaching/ mysvntest 或者： svn checkout http://10.0.0.6/svn/teaching/ mysvntest 最后取出来的新目录名，不给定就会用路径的最后一个目录名（如这里的teaching，这里给了就是mysvntest） 保持更新（update） 命令行： svn update 或者 svn up 多人合作时： 更新要经常频繁的做，尽量让问题及早暴露，便于处理。 提交代码前要更新，否则容易产生版本冲突。 通过第一步import后的那个目录并没有默认建立svn与远程的关系,需要手动从服务器checkout回服务器的版本到本地, 才算正式建立与远程的关系,才能直接 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>名词解释：</strong><br />
修订版（revision）：可以认为是某个文件在其生命周期内各个保存的快照，每个快照和一个时间区间对应。<br />
版本库（Repository）：存放修订版的数据库<br />
本地工作拷贝（Local working copy）：修订版在本地的副本<br />
版本的检入（Check in）：本地副本提交到服务器的版本库<br />
检出（Check out）：从服务器的版本库中取出修订版成为本地副本<br />
版本号的来源：有两种策略，基于文件的计数和基于仓库的计数，subversion使用后者<br />
标签（Tags）：为版本加一个名字，便于检出<br />
分支（Branches）：修订版打分支，以后可以平行修改，互不干扰<br />
合并（Merging）：将分支的修订版合并为一个新的修订版<br />
锁（Locking）：为修订版枷锁<br />
冲突（Conflict）：并发版本控制时防止修订版混乱的错误机制</p>
<p><strong>创建版本库</strong><br />
创建服务器端版本库<br />
命令行：<br />
svnadmin create file_path/repo_name</p>
<p><strong>初始导入（import）</strong><br />
通过命令行导入：<br />
svn import -m &#8220;init import&#8221; http://10.0.0.6/svn/teaching/<br />
该命令可将当前路径下文件导入到版本库中。</p>
<p><strong>检出（checkout）</strong><br />
通过命令行检入：<br />
svn co http://10.0.0.6/svn/teaching/ mysvntest<br />
或者：<br />
svn checkout http://10.0.0.6/svn/teaching/ mysvntest<br />
最后取出来的新目录名，不给定就会用路径的最后一个目录名（如这里的teaching，这里给了就是mysvntest）</p>
<p><strong>保持更新（update）</strong><br />
命令行：<br />
svn update<br />
或者<br />
svn up<br />
多人合作时：<br />
更新要经常频繁的做，尽量让问题及早暴露，便于处理。<br />
<strong>提交代码前要更新</strong>，否则容易产生版本冲突。<br />
通过第一步import后的那个目录并没有默认建立svn与远程的关系,需要手动从服务器checkout回服务器的版本到本地, 才算正式建立与远程的关系,才能直接 svn up……</p>
<p><strong>添加（add）</strong><br />
命令行：<br />
svn add file_path</p>
<p>告知svn服务器，添加目录和/或文件到服务器上，这个操作类似SQL的insert，但是并没有真的操作，直到commit。 </p>
<p><strong>提交改动（commit）</strong><br />
相当于通用概念：检入（checkin）。<br />
命令行：<br />
svn commit<br />
或者：<br />
svn ci<br />
<strong>要求：一般要注明修改的原因 </strong><br />
svn ci -m &#8220;修改bug #224&#8243;</p>
<p><strong>要求：提交之前要做更新</strong><br />
svn up<br />
svn ci -m &#8220;修改bug #224&#8243;</p>
<p><strong>还原改动</strong><br />
对应提交(commit)，要有类似回滚（rollback）的操作。<br />
svn revert</p>
<p><strong> “还原”已提交的改动</strong><br />
revert只适合未提交的情况。<br />
如果已经提交，发现问题，要回退到之前的修订版。<br />
首先：<br />
svn up<br />
让本地工作拷贝更新到最新状态。<br />
然后：<br />
svn log your_file_path<br />
查看文件日志，这时候提交时填写的说明信息就派上用场了。<br />
再，查看两个修订版之间的不同：<br />
svn diff -r 旧修订版序号:新修订版序号 your_file_path</p>
<p>决定用哪个旧的修订版号后，用旧的修订版号文件覆盖新的修订版号文件。<br />
svn merge -r 新修订版序号:旧修订版序号 your_file_path<br />
还需要：<br />
svn commit -m &#8220;恢复到某修订版（某修订版作废）&#8221;</p>
<p><strong>拷贝文件和目录</strong><br />
命令行：<br />
svn copy path/file_name newpath/new_file_name<br />
svn commit -m &#8220;xxxx&#8221;<br />
或者：<br />
svn cp path/file_name newpath/new_file_name<br />
svn commit -m &#8220;xxxx&#8221;<br />
svn的copy，是很重要的工具，版本分支和标签等概念都通过它实现。</p>
<p><strong>重命名目录/文件</strong><br />
命令行：<br />
svn move file_name new_file_name<br />
或者：<br />
svn mv file_name new_file_name</p>
<p><strong>处理合并冲突</strong><br />
svn默认不对文件加锁。<br />
如果不同人编辑了同一个文件的不同部分，提交时会自动合并。<br />
如果不同人编辑了同一个文件的同一部分，后提交者会报告合并冲突。<br />
解决方法（人工仲裁）：<br />
放弃改动；<br />
坚持你的改动，找到.mine的文件名，恢复为原文件名，然后执行：<br />
svn resolved file_name<br />
注意: 本子命令不会依语法来解决冲突或是移除冲突标记；它只是移除冲突的相关文件，然后让 PATH 可以再次提交。</p>
<p><strong>删除文件</strong><br />
将本地工作拷贝删除。<br />
命令行：<br />
svn delete file_path<br />
或者：<br />
svn del file_path</p>
<p><strong>版本库创建策略</strong><br />
单一的版本库保存一个项目。<br />
单一的版本库保存多个项目。<br />
多个版本库。 </p>
<p><strong>使用标签和分支</strong><br />
在svn中标签和分支都源于copy命令。<br />
3个约定俗成的目录：<br />
trunk：主干<br />
branches：分支<br />
tags：标签 </p>
<p><strong>发布分支：</strong><br />
svn cp -m &#8220;创建用于实现radio标签的分支&#8221; https://easymorse-simpletag.googlecode.com/svn/branches/simpletag_select_1 https://easymorse-simpletag.googlecode.com/svn/branches/simpletag_select_2</p>
<p><strong>切换分支： </strong><br />
svn switch https://easymorse-simpletag.googlecode.com/svn/branches/simpletag_select_2</p>
<p><strong>合并分支需要两个步骤：</strong> </p>
<p>合并操作<br />
svn merge -r 33:HEAD https://easymorse-simpletag.googlecode.com/svn/branches/simpletag_select_2<br />
或者：<br />
svn merge https://easymorse-simpletag.googlecode.com/svn/trunk/simpletag@HEAD https://easymorse-simpletag.googlecode.com/svn/branches/simpletag_select_1@HEAD<br />
提交。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=515</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>socks5 proxy 折腾记</title>
		<link>http://www.tsingfeng.com/?p=510</link>
		<comments>http://www.tsingfeng.com/?p=510#comments</comments>
		<pubDate>Sat, 27 Mar 2010 01:53:02 +0000</pubDate>
		<dc:creator>淡水河边</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[antinat]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[socks5]]></category>

		<guid isPermaLink="false">http://www.tsingfeng.com/?p=510</guid>
		<description><![CDATA[需要在服务器上装sock5 proxy，服务器平台是Redhat enterprise linux5,淡水要在有限的时间里去折腾它。 google之。 找到了socks5-v1.0r11编译报错:( 再google之。。。 又转找到ss5-3.6.4-3, 编译,又报错:( 时间有限，精力有限，关键是能力有限。。 最后google之。。。。。。 找到Antinat。看似很方便的样子。官网：http://antinat.sourceforge.net/ 下载： antinat-0.90-1.i386.rpm antinat-libs-0.90-1.i386.rpm 先rpm -ivh antinat-libs-0.90-1.i386.rpm 再rpm -ivh antinat-0.90-1.i386.rpm 搞定。 也可以下载：antinat-0.90.tar.bz2 编译安装。 tar jvxf antinat-0.90.tar.bz2 cd antinat-0.90 ./configure make install cp etc/antinat.xml.allopen /usr/local/etc/antinat.xml 配置端口： &#60;!-- Port to listen on --&#62; &#160; &#160; &#160; &#160; &#60;port&#160;value='1080'/&#62; 如无需认证，这样就完成了。我要加入认证帐号则，那么如下： vi&#160; /usr/local/etc/antinat.xml &#60;!-- &#60;user user='testuser' password='testpass'/&#62; --&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>需要在服务器上装sock5 proxy，服务器平台是Redhat enterprise linux5,淡水要在有限的时间里去折腾它。<br />
google之。<br />
找到了socks5-v1.0r11编译报错:(<br />
再google之。。。<br />
又转找到ss5-3.6.4-3, 编译,又报错:(<br />
时间有限，精力有限，关键是能力有限。。<br />
最后google之。。。。。。<br />
找到Antinat。看似很方便的样子。官网：http://antinat.sourceforge.net/<br />
下载：<br />
antinat-0.90-1.i386.rpm<br />
antinat-libs-0.90-1.i386.rpm<br />
先rpm -ivh antinat-libs-0.90-1.i386.rpm<br />
再rpm -ivh antinat-0.90-1.i386.rpm<br />
搞定。<br />
也可以下载：antinat-0.90.tar.bz2 编译安装。<br />
tar jvxf antinat-0.90.tar.bz2<br />
cd antinat-0.90<br />
./configure<br />
make install<br />
cp etc/antinat.xml.allopen /usr/local/etc/antinat.xml<br />
配置端口：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: #ffa500;">&lt;!-- Port to listen on --&gt;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">&lt;</span><span style="color: Green;">port</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">value</span><span style="color: Gray;">='</span><span style="color: #00008b;">1080</span><span style="color: Gray;">'</span><span style="color: Olive;">/&gt;</span></li></ol></div>
<p>如无需认证，这样就完成了。我要加入认证帐号则，那么如下：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Gray;">vi&nbsp; /usr/local/etc/antinat.xml</span></li>
<li><span style="color: #ffa500;">&lt;!-- &lt;user user='testuser' password='testpass'/&gt; --&gt;</span></li></ol></div>
<p>改为</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;">&lt;</span><span style="color: Green;">user</span><span style="color: Gray;"> </span><span style="color: #00008b;">user</span><span style="color: Gray;">='</span><span style="color: #00008b;">username</span><span style="color: Gray;">' </span><span style="color: #00008b;">password</span><span style="color: Gray;">='</span><span style="color: #00008b;">userpassword</span><span style="color: Gray;">'</span><span style="color: Olive;">/&gt;</span></li></ol></div>
<p>将
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;">&lt;</span><span style="color: Green;">select</span><span style="color: Gray;"> </span><span style="color: #00008b;">mechanism</span><span style="color: Gray;">='</span><span style="color: #00008b;">anonymous</span><span style="color: Gray;">'</span><span style="color: Olive;">/&gt;</span></li></ol></div>
<p>注销<br />
ok，运行吧：<br />
[root@testserver]antinat<br />
看看是否启动了<br />
[root@testserver]netstat -na|grep 1080<br />
tcp 0 0 0.0.0.0:1080 0.0.0.0:* LISTEN<br />
搞定了。X雷，X讯可以用了，嘿嘿嘿嘿（奸笑中……）</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsingfeng.com/?feed=rss2&amp;p=510</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
