2009年8月31日 星期一

linux date指令LANG / charset /encoding問題

#date
#一 8月 31 15:56:31 CST 2009

如果想要顯示「Mon Aug 31 15:58:51 CST 2009」

請先輸入以下指令
# LANG=C

2009年8月26日 星期三

google重新提交的網址

https://www.google.com/webmasters/tools/reconsideration

2009年8月25日 星期二

nmon performance: A free tool to analyze AIX and Linux performance

Usage notes: This nmon tool is NOT OFFICIALLY SUPPORTED. No warrantee is given or implied, and you cannot obtain help with it from IBM. If you have a question on nmon, please go on the Performance Tools Forum site (see Resources) so that others can find and benefit from the answers. To protect your email address from junk mail, you need to create a USER ID first (takes 20 seconds at most).
The nmon tool runs on:
AIX® 4.1.5, 4.2.0 , 4.3.2, and 4.3.3 (nmon Version 9a: This version is functionally established and will not be developed further.)
AIX 5.1, 5.2, and 5.3 (nmon Version 10: This version now supports AIX 5.3 and POWER5™ processor-based machines, with SMT and shared CPU micro-partitions.)
Linux® SUSE SLES 9, Red Hat EL 3 and 4, Debian on pSeries® p5, and OpenPower™
Linux SUSE, Red Hat, and many recent distributions on x86 (Intel and AMD in 32-bit mode)
Linux SUSE and Red Hat on zSeries® or mainframe
The nmon tool is updated roughly every six months, or when new operating system releases are available. To place your name on the e-mail list for updates, contact Nigel Griffiths.
Use this tool together with nmon analyser (see Resources), which loads the nmon output file and automatically creates dozens of graphs.
Introduction
The nmon tool is designed for AIX and Linux performance specialists to use for monitoring and analyzing performance data, including:
CPU utilization
Memory use
Kernel statistics and run queue information
Disks I/O rates, transfers, and read/write ratios
Free space on file systems
Disk adapters
Network I/O rates, transfers, and read/write ratios
Paging space and paging rates
CPU and AIX specification
Top processors
IBM HTTP Web cache
User-defined disk groups
Machine details and resources
Asynchronous I/O -- AIX only
Workload Manager (WLM) -- AIX only
IBM TotalStorage® Enterprise Storage Server® (ESS) disks -- AIX only
Network File System (NFS)
Dynamic LPAR (DLPAR) changes -- only pSeries p5 and OpenPower for either AIX or Linux
Also included is a new tool to generate graphs from the nmon output and create .gif files that can be displayed on a Web site.
See the README file for more details.
Benefits of the tool
The nmon tool is helpful in presenting all the important performance tuning information on one screen and dynamically updating it. This efficient tool works on any dumb screen, telnet session, or even a dial-up line. In addition, it does not consume many CPU cycles, usually below two percent. On newer machines, CPU usage is well below one percent.
Data is displayed on the screen and updated once every two seconds, using a dumb screen. However, you can easily change this interval to a longer or shorter time period. If you stretch the window and display the data on X Windows, VNC, PuTTY, or similar, the nmon tool can output a great deal of information in one place.
The nmon tool can also capture the same data to a text file for later analysis and graphing for reports. The output is in a spreadsheet format (.csv).
Installing the tool
The tool is a stand-alone binary file (a different file for each AIX or Linux version) that you can install in five seconds, probably less if you type fast. Installation is simple:
Copy the nmonXXX.tar.Z file to the machine. If using FTP, remember to use binary mode.
Note: Version XXX replaces this example.
To uncompress the file, run uncompress nmonXX.tar.Z.
To extract the files, run tar xvf nmonXX.tar.
Read the README file.
To start the nmon tool, type nmon.
If you are the root user, you might need to type ./nmon.
Extra notes for using nmon 9 for AIX 4 only
You must be the root user or allow regular users to read the /dev/kmem file by typing the following command (as root):
chmod ugo+r /dev/kmem

If you want the disk statistics, then also run (as root):
chdev -l sys0 -a iostat=true

How to run the tool interactively
For running the tool interactively, read the front page of the file for a few hints. Then start the tool and use the one-key commands to see the data you want. For example, to get CPU, Memory, and Disk statistics, start nmon and type:
cmd

How to get help information while running interactively
Press the h key.
Additional help information
For additonal help information, try the following:
Type the nmon -? command for brief details.
Type the nmon -h command for full details.
Read the README file.
How to capture the data to a file for later analysis and graphing
Run nmon with the -f flag. See nmon -h for the details. But as an example, try to run nmon for an hour capturing data snapshots every 30 seconds by using: Â Â Â Â
nmon -f -s 30 -c 120
nmon -fT -s 30 -c 120

The second line also captures the top processes. Both of these create the output file in the current directory called: Â Â Â Â
_date_time.nmon

This file is in a comma-separated values (CVS) format and can be imported into a spreadsheet directly. If you are using Lotus® 1-2-3, the file needs to be sorted. (This is not required for the Excel version of the nmon analyser.) On AIX, follow this example: Â Â Â Â
sort -A mymachine_311201_1030.nmon > xxx.csv

Notes to save you time:
To load the nmon data capture file into a spreadsheet, check the spreadsheet documentation for loading CVS data files (.csv). Many spreadsheets accept this data as just one of the possible files to load or provide an import function to do this. Many spreadsheets have a fixed number of columns and rows. I suggest you collect a maximum of 300 snapshots to avoid hitting these issues.
When you are capturing data to a file, nmon disconnects from the shell to ensure that it continues running, even if you log out. This means that nmon can appear to crash, even though it's still running in the background. To see if the process is still running, type:
ps ?ef | grep nmon

Read the README file for more information about which version of nmon to run on your particular operating system.
nmon Version 10 for AIX 5 no longer uses /dev/kmem, but only public APIs. So, you don't have to chage the permissions on /dev/kmem, and there is no need to have 32- and 64-bit versions of nmon.
For AIX 5.1, 5.2, and 5.3, use nmon 10.
On AIX, don't report lslpp -Lcq bos.?p core dumps on AIX 5.1, about ML03 onwards. Also, WLM stats go missing after upgrading to AIX 5.2 ML5 to Nigel Griffiths, as these are AIX bugs. These are avoided by using nmon Version 10.
Don't use Microsoft® Windows® Telnet and use a larger window than 80 x 25 characters. Many developers use VNC and PuTTY to display nmon from a Windows machine -- why not do the same!
New features for nmon on AIX Version 10
New Features Description
Starting up There is also now a small shell script called "nmon" that starts the right nmon version. Place this script and nmon binaries in your $PATH and type: nmon. This version is now only compiled in 32-bit mode. So, it runs on 32- and 64-bit hardware. The idea is to make it easier to install and run.
N = NFS NFS is completely new for nmon 10.
p = Partitions This is for shared CPU partitions information -- the big p5/AIX5.3 feature.
C = CPU This is for machines with 32 plus CPUs -- up to 128 logical CPUs by demand.
c = CPU Details your physical CPU use -- if you are on a POWER5 with AIX 5.3 and in a shared CPU environment.
S = Subclass This is for WLM subclasses -- by request.
a = Disk adapters Gives you details of the disk adapter -- like their full type.
r = Resources This includes your CPU speed in MHz.
k = Kernel Gives some new fields.
L = Large pages Gives you large-page stats -- popular with high-performance guys.
D = Disk Gives you more information about your disks, disk type sizes, free, volume groups, adapter, and so forth.
n = Network Gives you information about your network adapters details, MTU, and errors.
m = Memory Gives you more details on where your memory is going, system (kernel) and processes, and active virtual memory.
-B This is a start-up option to remove the boxes.
Sample output for nmon 10 for AIX 5
Figure 1 below is a sample of the screen output. It shows the opening screen for AIX 5, with lots of useful information.

Figure 1. Sample output for nmon 10 for AIX 5

Figure 2 illustrates the details for CPU (this is a 4 CPU POWER5 machine with SMT switched on), memory use, kernel internal statistics, and disks statistics. Note: This logical partition (LPAR) is using six times its entitlement in half a CPU.

Figure 2. CPU details

Figure 3 shows the details of the network, NFS statistics, and journal filesystem use.

Figure 3. Network details

The details of the POWER5 shared processor micro-partitions statistics are shown in Figure 4 below.

Figure 4. LPAR details

Figure 5 illustrates the details of the Linux version of nmon, showing the CPU (this is a 2 CPU POWER5 machine with SMT switched on), LPAR statistics, memory use, network statistics, file system use, and disks statistics. Note: The physical CPU of this LPAR is only available with SUSE SLES9 Service Pack 1 and Red Hat EL 4 Update 1.

Figure 5. Linux version of nmon

Figure 6 shows the OS details of the machine, disk statistics (detailed mode), and the top processes.

Figure 6. Linux version of nmon continued

Obtaining the tool
The following download options are available:
You can download nmon and its tools from IBM Wiki at http://www-941.haw.ibm.com/collaboration/wiki/display/WikiPtype/nmon.
Check out the Performance Tools forum for nmon questions and ideas at http://www-03.ibm.com/systems/p/community/.

Resources
Learn
"nmon analyser -- A free tool to produce AIX performance reports" (developerWorks, April 2006): Produce a wealth of report-ready graphs from nmon output.

Check out the following IBM Redbooks for additional information on performance:
Understanding IBM pSeries Performance and Sizing, SG24-4810-01, Febraruary 2001
Database Performance on AIX in the DB2 UDB and Oracle Environments, SG24-5511, January 2003
AIX 5L Performance Tools Handbook,SG24-6039, August 2003

Check out other articles and tutorials written by Nigel Griffiths:
AIX and UNIX zone
Across IBM and developerWorks

"AIX 5 performance series: CPU monitoring and tuning": Browse through this article to get rid of your CPU bottlenecks and improve performance.

Search the AIX and UNIX library by topic:
System administration
Application development
Performance
Porting
Security
Tips
Tools and utilities
Java™ technology
Linux
Open source

AIX and UNIX: The AIX and UNIX developerWorks zone provides a wealth of information relating to all aspects of AIX systems administration and expanding your UNIX skills.

New to AIX and UNIX: Visit the New to AIX and UNIX page to learn more about AIX and UNIX.

AIX 5L™ Wiki: A collaborative environment for technical information related to AIX.

IBM Virtual Innovation Center for Hardware: This site is the primary source for all System p AIX development.

Safari bookstore: Visit this e-reference library to find specific technical resources.

developerWorks technical events and webcasts: Stay current with developerWorks technical events and webcasts.

Podcasts: Tune in and catch up with IBM technical experts.

Get products and technologies
IBM trial software: Build your next development project with software for download directly from developerWorks.

nmon: Download nmon and its tools.

Discuss
Participate in the developerWorks blogs and get involved in the developerWorks community.

Participate in the AIX and UNIX forums:
AIX 5L -- technical forum
AIX for Developers Forum
Cluster Systems Management
IBM Support Assistant
Performance Tools -- technical
Virtualization -- technical
More AIX and UNIX forums

nmon questions: Check out the Performance Tools forum for nmon questions and ideas.

About the author
Nigel Griffiths works in the IBM eServer® pSeries Technical Support Advanced Technology Group. He specialises in performance, sizing, tools, benchmarks, and Oracle RDBMS. The nmon tool was developed to support benchmarks and performance tuning for internal use, but by popular demand is given away to deserving friends. If you have a question on nmon, please go on the Performance Tools Forum site (see Resources) so that others can find and benefit from the answers. To protect your email address from junk mail, you need to create a USER ID first (takes 20 seconds at most).

摘自:http://www.ibm.com/developerworks/aix/library/au-analyze_aix/

2009年8月23日 星期日

[PHP] Is there a way to get a variable name as a string?

On rare occasions, you may need to retrieve a variable name as a string.

This handy little function retreives the name of the variable:


$my_var = 1;
echo var_name ($my_var);
?>

will give 'my_var'.


I started trying to find a solution to this problem, because I needed such a function and because questions about it appeared on several mailing lists and forums:
[PHP] Is there a way to get a variable name as a string?

most people said it was not possible...
Re: [PHP] Is there a way to get a variable name as a string?
From: Rasmus Lerdorf

In PHP it is possible to use a variable if you have its name as a string :



$iVarName = 'MaxSize';
$$iVarName = 10;
echo $MaxSize;

?>

But PHP does not natively include a way to get the name of a given variable.

This might be useful in situations where you design a function with a parameter passed by reference and you need to know which variable was sent as a parameter for this function.



The solution :

The following function retreives the variable name from a given variable:



function var_name (&$iVar, &$aDefinedVars)
{
foreach ($aDefinedVars as $k=>$v)
$aDefinedVars_0[$k] = $v;

$iVarSave = $iVar;
$iVar =!$iVar;

$aDiffKeys = array_keys (array_diff_assoc ($aDefinedVars_0, $aDefinedVars));
$iVar = $iVarSave;

return $aDiffKeys[0];
}

?>

This function has to be called with a second parameter always set to the result of the function "get_defined_vars()":



var_name($iVar, get_defined_vars());

?>



How does it work ?

var_name compares the result of the function "get_defined_vars()" before and after modification of the variable whose name we want to find.

The initial set of defined variables passed as a parameter to var_name is first stored in "$aDefinedVars_0" and compared later.

Before modifying the value of the variable, its value is saved in $iVarSave.

$iVar is then changed to something different :
$iVar=!$iVar;

$aDefinedVars keeps track of this modification and can be compare to $aDefinedVars_0 (its initial value). The difference is the variable we modified and we can get its name as a string in the key value of the array record.

The value of the variable is restored to its initial value kept in $iVarSave and the name of the variable is returned.



Example :

The following PHP code shows the function var_name in action:



$v_1 = 1; echo 'var $',var_name ($v_1, get_defined_vars()),' = ',var_dump($v_1),'
';
$v_2 = 4; echo 'var $',var_name ($v_2, get_defined_vars()),' = ',var_dump($v_2),'
';
$v_3 = 'qwerty'; echo 'var $',var_name ($v_3, get_defined_vars()),' = ',var_dump($v_3),'
';
$v_4 = array('aa'=>'11','bb'=>'22',3); echo 'var $',var_name ($v_4, get_defined_vars()),' = ',var_dump($v_4),'
';
$v_5 = &$v_2; echo 'var $',var_name ($v_5, get_defined_vars()),' = ',var_dump($v_5),'
';
echo 'var $',implode (' / $',var_name ($v_5, get_defined_vars(),true)),' = ',var_dump($v_5),'
';

function test()
{
$v_1 = 'qwerty'; echo 'var $',var_name ($v_1, get_defined_vars()),' = ',var_dump($v_1),'


';
global $v_5; echo 'var $',var_name ($v_5, get_defined_vars()),' = ',var_dump($v_5),'


';
}

test();

?>

var_name can retreive the name of the variable in every case.



Application :

The most direct application of this function is, of course, a "dump" function.
Just call this "dump" function with the variable you want to monitor - do not forget to add the "get_defined_vars()" parameter...



function dump(&$v, &$aDefinedVars)
{
echo '
$',implode (' / $',var_name ($v, $aDefinedVars, true)),' = ',print_r($v, true),'


';
}

dump($v_4, get_defined_vars());

?>



Going further :

The function var_name can be enhanced by adding the parameter $bShowAllRef to show, if set to true, all the references relating to the variable passed as a parameter:



function var_name (&$iVar, &$aDefinedVars, $bShowAllRef=false )
{
foreach ($aDefinedVars as $k=>$v)
$aDefinedVars_0[$k] = $v;

$iVarSave = $iVar;
$iVar =!$iVar;

$aDiffKeys = array_keys (array_diff_assoc ($aDefinedVars_0, $aDefinedVars));
$iVar = $iVarSave;

return ($bShowAllRef? $aDiffKeys: $aDiffKeys[0]);
}

?>

That's it ! You can download the function here.

This code is free to use and published under the GPL license.

function var_name (&$iVar, &$aDefinedVars)
{
foreach ($aDefinedVars as $k=>$v)
$aDefinedVars_0[$k] = $v;

$iVarSave = $iVar;
$iVar =!$iVar;

$aDiffKeys = array_keys (array_diff_assoc ($aDefinedVars_0, $aDefinedVars));
$iVar = $iVarSave;

return $aDiffKeys[0];
}

摘自:http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php

2009年8月19日 星期三

RewriteRule 記事

想用RewriteRule把網址轉成 .html

www.xxx/test.php
www.xxx/1st/test2.php
www.xxx/1st/2st/test3.php

轉成
www.xxx/test.html
www.xxx/1st/test2.html
www.xxx/1st/2st/test3.html

#啟動 Rewrite
RewriteEngine On
#設定重寫的目錄
RewriteBase /
#設定重寫規則
RewriteRule ^(.+)\.htm$ $1.php

URL Rewriting Engine

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

apache RewriteRule 的問題

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html


RewriteRule IIS映射

安裝說明:

1、在IIS的Isapi上新增這個篩選器,篩選器名稱 re,可執行檔案選擇 Rewrite.dll ;
2、設定httpd.ini檔案

RewriteRule /news/(\d+)\.html /jsp/news\.jsp\?id=$1 [N,I]
表示將news.jsp?id=95 轉換成news/95.html

以此類推,如果你有更多的參數,則增加相應的(\d+),而後面的id=$1,則增加id=$2,等等。

目前較為普遍的動態網頁包括asp,php,jsp,shtml,jhtml,cgi......甚至還有一些自己定義的,比如:aspx,do,index,hello等等。表現形式為:news.asp?id=95。建議讀者通過re_write將其轉換成news/95.html,以便於google對改網頁的識別。

re_write是iis裡的一個模塊,你可以從http://www.GoogleDmoz.com/dirtool/re_write.zip

當需要將news.jsp?id=95的映射成news/95.html時,只需設定httpd.ini檔案:
RewriteRule /news/(\d+)\.html /news\.jsp\?id=$1 [N,I]
這樣就把 /news/95.html 這樣的請求映射成了 /news.jsp?id=95

然後你在連接處這樣寫:95新聞
如果你的新聞是通過資料庫循環讀取出來的,那麼寫法是:
while(rs.next())
{
String id = (String)rs.getString('id');
out.print('');
out.print('95新聞');
out.print('
');
}

如果你在處理資料翻頁,那麼寫法是:

More_<%=Page%>_<%=type%>.html (註:page是翻頁頁數,type是資料類型)
表現形式:More_1_95.html

如果翻下一頁,則為:More_2_95.html,繼續下一頁的循環,則是:
More_3_95.html,以此類推。

不過你需要在httpd.ini檔案中增加以下代碼:
RewriteRule /More_(\d+)_(\d+)\.html /jsp/more\.jsp\?page=$1&type=$2 [N,I]

如果你的動態程式有多個參數需要傳遞,那麼就增加多個(\d+)即可,如下:

RewriteRule /More_(\d+)_(\d+)_(\d+)\.html /jsp/more\.jsp\?page=$1&type=$2&type2=$3 [N,I]

翻頁處理表現形式是:More_1_95.html

Apache的Mod_rewrite

Syntax: RewriteRule Pattern Substitution [flags]

  一條RewriteRule指令,定義一條重寫規則,規則間的順序非常重要。對Apache1.2及以後的版本,模板(pattern)是一個POSIX正則式,用以匹配當前的URL。當前的URL不一定是用記最初提交的URL,因為可能用一些規則在此規則前已經對URL進行了處理。


  對mod_rewrite來說,!是個合法的模板前綴,表示「非」的意思,這對描述「不滿足某種匹配條件」的情況非常方便,或用作最後一條默認規則。當使用!時,不能在模板中有分組的通配符,也不能做後向引用。


  當匹配成功後,Substitution會被用來替換相應的匹配,它除了可以是普通的字符串以外,還可以包括:

1. $N,引用RewriteRule模板中匹配的相關字串,N表示序號,N=0..9
2. %N,引用最後一個RewriteCond模板中匹配的資料,N表示序號
3. %{VARNAME},服務器變數
4. ${mapname:key|default},映射函數呼叫


這些特殊內容的擴展,按上述順序進行。
  一個URL的全部相關部分都會被Substitution替換,而且這個替換過程會一直持續到所有的規則都被執行完,除非明確地用L標誌中斷處理過程。
  當susbstitution有」-」前綴時,表示不進行替換,只做匹配檢查。
  利用RewriteRule,可定義含有請求串(Query String)的URL,此時只需在Sustitution中加入一個?,表示此後的內容放入QUERY_STRING變數中。如果要清空一個QUERY_STRING變數,只需要以?結束Substitution串即可。
  如果給一個Substitution增加一個


1. 'redirect|R [=code]' (強制重定向)
  給當前的URI增加前綴


2. 'forbidden|F' (強制禁止訪問URL所指的資源)
  立即傳回狀態值403 (FORBIDDEN)的應答包。將這個標誌與合適的RewriteConds 聯合使用,可以阻斷訪問某些URL。


3. 'gone|G' (強制傳回URL所指資源為不存在(gone))
  立即傳回狀態值410 (GONE)的應答包。用這個標誌來標記URL所指的資源永久消失了.


4. # 'proxy|P' (強制將當前URL送往代理模塊(proxy module))
  這個標誌,強制將substitution當作一個發向代理模塊的請求,並立即將共送往代理模塊。因此,必須確保substitution串是一個合法的URI (如, 典型的情況是以


5. 'last|L' (最後一條規則)
  中止重寫流程,不再對當前URL施加更多的重寫規則。這相當於perl的last命令或C的break命令。


6. 'next|N' (下一輪)
  重新從第一條重寫規則開始執行重寫過程,新開的過程中的URL不應當與最初的URL相同。 這相當於Perl的next命令或C的continue命令. 千萬小心不要產生死循環。


7. # 'chain|C' (將當前的規則與其後續規則綑綁(chained))
  當規則匹配時,處理過程與沒有綑綁一樣;如果規則不匹配,則綑綁在一起的後續規則也不在檢查和執行。


8. 'type|T=MIME-type' (強制MIME類型)
  強制將目標檔案的MIME-type為某MIME類型。例如,這可用來模仿mod_alias模塊對某目錄的ScriptAlias指定,通過強制將該目錄下的所有檔案的類型改為 「application/x-httpd-cgi」.


9. 'nosubreq|NS' (used only if no internal sub-request )
  這個標誌強制重寫引擎跳過為內部sub-request的重寫規則.例如,當mod_include試圖找到某一目錄下的默認檔案時 (index.xxx),sub-requests 會在Apache內部發生. Sub-requests並非總是有用的,在某些情況下如果整個規則集施加到它上面,會產生錯誤。利用這個標誌可排除執行一些規則。


10. 'nocase|NC' (模板不區分大小寫)


  這個標誌會使得模板匹配當前URL時忽略大小寫的差別。

11. 'qsappend|QSA' (追加請求串(query string))
  這個標誌,強制重寫引擎為Substitution的請求串追加一部分串,則不是替換掉原來的。借助這個標誌,可以使用一個重寫規則給請求串增加更多的資料。


12. 'noescape|NE' (不對輸出結果中的特殊字符進行轉義處理)
  通常情況下,mod_write的輸出結果中,特殊字符(如'%', '$', ';', 等)會轉義為它們的16進制形式(如分別為'%25', '%24', and '%3B')。這個標誌會禁止mod_rewrite對輸出結果進行此類操作。 這個標誌只能在 Apache 1.3.20及以後的版本中使用。


13. 'passthrough|PT' (通過下一個處理器)
  這個標誌強制重寫引擎用filename字段的值來替換內部request_rec資料結構中uri字段的值。. 使用這個標誌,可以使後續的其它URI-to-filename轉換器的Alias、ScriptAlias、Redirect等指令,也能正常處理RewriteRule指令的輸出結果。用一個小例子來說明它的語義:如果要用mod_rewrite的重寫引擎將/abc轉換為/def,然後用mod_alas將/def重寫為ghi,則要:

RewriteRule ^/abc(.*) /def$1 [PT]
Alias /def /ghi

如果PT標誌被忽略,則mod_rewrite也能很好完成工作,如果., 將 uri=/abc/... 轉換為filename=/def/... ,完全符合一個URI-to-filename轉換器的動作。接下來 mod_alias 試圖做 URI-to-filename 轉換時就會出問題。
注意:如果要混合都含有URL-to-filename轉換器的不同的模塊的指令,必須用這個標誌。最典型的例子是mod_alias和mod_rewrite的使用。


14. 'skip|S=num' (跳過後面的num個規則)
  當前規則匹配時,強制重寫引擎跳過後續的num個規則。用這個可以來模仿if-then-else結構:then子句的最後一條rule的標誌是skip=N,而N是else子句的規則條數。


15. 'env|E=VAR:VAL' (設定環境變數)
  設定名為VAR的環境變數的值為VAL,其中VAL中可以含有正則式的後向引用($N或%N)。這個標誌可以使用多次,以設定多個環境變數。這兒設定的變數,可以在多種情況下被引用,如在XSSI或CGI中。另外,也可以在RewriteCond模板中以%{ENV:VAR}的形式被引用。


16. 注意:一定不要忘記,在服務器範圍內的配置檔案中,模板(pattern)用以匹配整個URL;而在目錄範圍內的配置檔案中,目錄前綴總是被自動去掉後再進行模板匹配的,且在替換完成後自動再加上這個前綴。這個功能對很多種類的重寫是非常重要的,因為如果沒有去前綴,則要進行父目錄的匹配,而父目錄的訊息並不是總能得到的。一個例外是,當substitution中有http://打頭時,則不再自動增加前綴了,如果P標誌出現,則會強制轉向代理。


注意:如果要在某個目錄範圍內啟動重寫引擎,則需要在相應的目錄配置檔案中設定「RewriteEngine on」,且目錄的「Options FollowSymLinks」必須設定。如果管理員由於安全原因沒有打開FollowSymLinks,則不能使用重寫引擎。

http://hostname開頭),否則會從代理模塊得到一個錯誤. 這個標誌,是ProxyPass指令的一個更強勁的實現,將遠程請求(remote stuff)映射到本地服務器的名字空間(namespace)中來。

  注意,使用這個功能必須確保代理模塊已經編譯到Apache 服務器程式中了. 可以用「httpd -l 」命令,來檢查輸出中是否含有mod_proxy.c來確認一下。如果沒有,而又需要使用這個功能,則需要重新編譯``httpd''程式並使用mod_proxy有效。 http://thishost[:thisport]/, 從而生成一個新的URL,強制生成一個外部重定向(external redirection,指生的URL發送到客戶端,由客戶端再次以新的URL發出請求,雖然新URL仍指向當前的服務器). 如果沒有指定的code值,則HTTP應答以狀態值302 (MOVED TEMPORARILY),如果想使用300-400(不含400)間的其它值可以通過在code的位置以相應的數字指定,也可以用標誌名指定: temp (默認值), permanent, seeother.

注意,當使用這個標誌時,要確實substitution是個合法的URL,這個標誌只是在URL前增加http://thishost[:thisport]/前綴而已,重寫操作會繼續進行。如果要立即將新URL重定向,用L標誌來中重寫流程。 http://thishost[:port]的前綴,則mod_rewrite會自動將此前綴去掉。因此,利用http://thisthost做一個無條件的重定向到自己,將難以奏效。要實現這種效果,必須使用R標誌。

Flags是可選參數,當有多個標誌同時出現時,彼此間以逗號分隔。

摘自:http://bbs.flash2u.com.tw/dv_rss_xhtml_54_92453_4.html

2009年8月18日 星期二

Big5 form serialize後的編碼

Form(中文big5未urlencode) => form serialize => browser => 中文utf8 => php (中文utf8)
Form(中文big5已urlencode) => form serialize => browser => urlencode碼 => php urldecode (中文big5)

2009年8月17日 星期一

[Debug]WordPress Email Publish 無法發佈到MSN Space

將權限開放給合法的「寄件者」即可

outlook -> 打開信件 -> 點選寄件者 -> 電子郵件地址

2009年8月12日 星期三

最近跟Yahoo網站合作,共同製作某一頻道

Yahoo使用Scanmus發現我們網站有XSS漏洞
網路上有很多XSS filter
目前是參考OWASP_PHP_Filters的過濾機制
覺得很不錯

2009年8月11日 星期二

Static Routes in Redhat 9 - New isn't always better

Overview

With the introduction of Redhat version 8 and continued into version 9, the /etc/sysconfig/static-routes file no longer seems to function correctly.

Linux static routes changed in 8.0 to a new format. Now you are to create a file in /etc/sysconfig/network-scripts for each Ethernet interface you wish to create static routes on.

Example:

touch /etc/sysconfig/network-scripts/route-eth0

The syntax for this file is different from the traditional route format used in /etc/sysconfig/static-routes . Redhat has yet to document the change on their web site as of June 2003.

Syntax based on a usenet post go to /etc/sysconfig/network-scripts, make a file called route-devicename (ex: route-eth0) and populate it with your static routes for that device so if you wanted to make a static route to the 192.168.0.0/24 network through 152.3.182.5 type:

192.168.0.0/24 via 152.3.182.5

Persistent static routes for ANY linux distribution

You may use this method to add static routes and it will work under any Linux distribution. However, it is considered by some a 'hack' or the 'ugly way'.

Edit your /etc/rc.local file and add your static routes using the route statement.

Example:

route add -net 10.10.98.0 netmask 255.255.255.0 gw 10.164.234.132 dev eth1
route add -net 10.164.234.96 netmask 255.255.255.252 gw 10.164.234.132 dev eth1
route add -net 10.164.234.112 netmask 255.255.255.240 gw 10.164.234.132 dev eth1

Force the old static-routes file to work under Redhat 9

Clear out the new /etc/sysconfig/network-scripts/ifup-routes script so that you can populate it with the original shell script from Redhat 7.x.

cat /dev/null > /etc/sysconfig/network-scripts/ifup-routes
vi /etc/sysconfig/network-scripts/ifup-routes

type in the following (or copy and paste) not including the tilde lines:

#!/bin/sh

# adds static routes which go through device $1

if [ "$1" = "" ]; then
echo "usage: $0 "
exit 1
fi

if [ ! -f /etc/sysconfig/static-routes ]; then
exit 0
fi

# note the trailing space in the grep gets rid of aliases
grep "^$1 " /etc/sysconfig/static-routes | while read device args; do
/sbin/route add -$args $device
done
grep "^any " /etc/sysconfig/static-routes | while read ignore type net netmask mask bogus dev ; do
if [ "$dev" = "$1" ]; then
/sbin/route add -$type $net $netmask $mask $dev
fi
done

Remember to use /etc/sysconfig/network for your default gateway

If you only intend to add one route, your default gateway, then you need not worry about the static routes file or using the route command. Simply add your default gateway in /etc/sysconfig/network.

Example

NETWORKING=yes
HOSTNAME="hostname.linux.org"
GATEWAY="10.164.234.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"

2009年8月4日 星期二

yum install php-mysql Error: mysql conflicts with MySQL-server-community

MySQL 5.1がGAになってからしばらく経ったのに使った事無かったので、今やっている実験プロジェクトで採用してみた。

CentOSの標準パッケージだとmysqlのバージョンは5.0。mysql関連パッケージもmysql-5.0に依存しているので、その辺をクリアする必要がある。

とりあえず手順やエラーメッセージのみを簡潔に説明。

1. 既存のMySQLパッケージを(インストールされていれば)アンインストール

2. MySQL公式サイトからのRPMパッケージをインストール
この辺りからパッケージをダウンロード。使用したのは以下のもの。

* MySQL-client-community-5.1.34-0.rhel5.i386.rpm
* MySQL-server-community-5.1.34-0.rhel5.i386.rpm
* MySQL-shared-community-5.1.34-0.rhel5.i386.rpm

rpm -ivhで普通にインストールすればOK。

ここまでは特に問題ないと思うんだけど、php-mysqlをインストールしようとして問題発生。


3. php-mysqlのインストール

[root@host downloads]# yum install php-mysql
(中略)
mysql-5.0.45-7.el5.i386 from base has depsolving problems
--> mysql conflicts with MySQL-server-community
Error: mysql conflicts with MySQL-server-community

php-mysqlはCentOS標準のmysqlパッケージに依存してるんだけど、mysqlは先ほどインストールしたMySQL-server-communityと競合している。

rpm コマンドなら出来るけど、yumコマンドだと依存性を無視したインストールが出来ない。なので、php-mysqlをダウンロードしてrpmコマンドでインストールする必要がある。その為にはyum-utilsパッケージに含まれているyumdownloaderコマンドを使う。

[root@host downloads]# yum install yum-utils
[root@host downloads]# yumdownloader php-mysql
[root@host downloads]# rpm -ivh php-mysql-5.1.6-23.2.el5_3.i386.rpm
エラー: 依存性の欠如:
libmysqlclient.so.15 は php-mysql-5.1.6-23.2.el5_3.i386 に必要とされています
libmysqlclient.so.15(libmysqlclient_15) は php-mysql-5.1.6-23.2.el5_3.i386 に必要とされて います
php-pdo は php-mysql-5.1.6-23.2.el5_3.i386 に必要とされています

とりあえずphp-pdoは普通にyumでインストール。

libmysqlclient.soに関してだけど、MySQL 5.1をインストールするとインストールされるのはlibmysqlclient.so.16。php-mysql-5.1が必要としているのは libmysqlclient.so.15。ここで選択肢は2つかなぁと思う。

* 16から15にシンボリックリンクを貼る
* libmysqlclient.so.15をインストール

前者は簡単なので、今回は後者の方法を試してみた。libmysqlclient.so.15はmysql-5.0.45-7.el5.i386.rpmに含まれている。従って以下のような方法で取り出して、/usr/lib以下にコピー。

[root@host downloads]# yumdownloader mysql
[root@host downloads]# rpm2cpio mysql-5.0.45-7.el5.i386.rpm | cpio -id
[root@host downloads]# cp -a usr/lib/mysql/libmysqlclient* /usr/lib

これで準備完了。後は依存関係を無視してphp-mysqlをインストールして、apacheを再起動すれば、PHPのMySQL関連関数を使えるようになる。

[root@host downloads]# rpm -ivh --nodeps php-mysql-5.1.6-23.2.el5_3.i386.rpm
[root@host downloads]# /etc/init.d/httpd restart


摘自:http://www.kazu.tv/blog/archives/000770.html

wibiya widget