2009/9/22

php 常用的特殊符號

http://hi.baidu.com/xinghuali/blog/item/7a735782a9b4a9a50cf4d236.html

其中比較特殊的簽號

其他運算符號
        $         變數符號             
        &        變數的指標(加在變數前)
        @       不顯示錯誤信息(加在函數前)
        ->        物件的方法或者屬性
        =>       陣列的元素值
        ? :       三元運算子  

flash & p2p

flash 10支援p2p了(驚)!!

之前用ElectroServer開發多人連線遊戲
總覺得這所有的訊號都要經過server才能傳遞給對方

推想如果要建多人視訊,主機的loading不就大到爆

不小心看到這則新聞
http://waterxbread.blogspot.com/2009/08/flash-p2p.html

flash 10 支援p2p了!!

p2p的好處就是可以比較不重要的訊息透過這種方式傳遞
像是不需要存取到資料庫的訊息
如多人遊戲中的對談
例如多人遊戲中的兩個人在pk,撇開作弊因素,過程的打法不需要讓伺服器知道,最後的結果告訴伺服器就好

可以推測,之後facebook上的小遊戲會有新一波改變

2009/9/20

vim常用語法

搜尋取代
1代表第一行,$是最後一行,搜尋news字串,取代成topic字串,s代表搜尋取代
:1,$s/news/topic/g

搜尋取代,搜尋全部的行可直接用%
:%s/news/topic/g

搜尋else字串,公用else取代topicnews
用正規表示式將news框起來,並代到取得字串的\1
多種字串框時,則用\1、\2、\3……
:%s/^\(news\)/topic\1/g


將每一行前面加上#號
:1,$s/^/#/g


全文自動排版
gg=G


yy 剪下行
y2 剪下本行至下兩行
p 貼上行

一些簡單的screen語法

一些簡單的screen語法

screen -U -S sname 以utf-8的編碼,並以sname為標籤建立screen ,並

-U 以utf8編碼
-r 回覆上次登入
-d 強制回覆
-ls 列出所有的screen


進入screen狀態後的操作

Ctrl+a c 開啟新的視窗,並同時切換到這個新的視窗

Ctrl+a n 或 C-a (space) 切換到下一個視窗

Ctrl+a p 切換到上一個視窗

Ctrl+a 0 切換到第 0 個視窗

Ctrl+a (1..9) 切換到第 (1..9) 個視窗

var_dump & print_r

以前寫php常用
print_r把整個陣列的內容印出來

學弟跟我說了另一個 var_dump
可以把整個陣列印出來
另外還補上陣列內容的形態

參考網址
http://tw.php.net/var_dump

2009/9/5

移除removexss攻擊語法

xss攻擊

何謂xss攻擊
可參考http://anti-hacker.blogspot.com/2008/01/xsscross-site-script.html
簡單的說
就是在post欄位中塞一些惡意語法

以下是移除xss語法的function
參考http://kallahar.com/smallprojects/php_xss_filter_function.php

function RemoveXSS($val) {
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
// this prevents some character re-spacing such as
// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);

// straight replacements, the user should never need these since they're normal characters
// this prevents like
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < val =" preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i'," val =" preg_replace('/(�{0,8}'.ord($search[$i]).';?)/'," ra1 =" Array('javascript'," ra2 =" Array('onabort'," ra =" array_merge($ra1," found =" true;" found ="=" val_before =" $val;" i =" 0;" pattern =" '/';" j =" 0;"> 0) {
$pattern .= '(';
$pattern .= '(&#[xX]0{0,8}([9ab]);)';
$pattern .= '|';
$pattern .= '|(�{0,8}([9|10|13]);)';
$pattern .= ')*';
}
$pattern .= $ra[$i][$j];
}
$pattern .= '/i';
$replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); // add in <> to nerf the tag
$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
if ($val_before == $val) {
// no replacements were made, so exit the loop
$found = false;
}
}
}
return $val;
}