EZBOY的工作日誌
PHP,MySQL,APACHE,JQUERY,AJAX,UBUNTU
2011-03-31
利用curl取得http header訊息
$remoteFile = "http://www.google.com/";
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
MySQL 欄位排序-特定的值
ORDER BY FIELD(CONVERT(XXX using binary),'A1','A2','A3')
2011-02-03
[ubuntu]redir port forward 工具
$ redir --lport 81 --caddr=192.168.0.1 --cport=80
此範例就是把本機port 81轉到192.168.0.1的port 80下
安裝:apt-get install redir
2011-01-20
ubuntu查閱主機記錄
查閱想非法入侵的記錄(被拒)
more /var/log/auth.log |grep "refused"
查閱主機連線的記錄(允許)
more /var/log/auth.log |grep "Accepted"
當然您的主機在/etc/hosts.allow ,與/etc/hosts.deny
要事先設定好連線範圍
http://free.chc.edu.tw/~chi/blog/index.php?load=read&id=36
php連接mssql2005
<?php
$serverName = "127.0.0.1";
$connectionInfo = array("Database"=>"TestDB","UID"=>"test","PWD"=>"test");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn) {
echo "Connection established.<br>";
} else {
echo "Connection could not be established.<br>";
die(print_r(sqlsrv_errors(), true));
exit();
}
$sql = "select * from T_Employee";
$result = sqlsrv_query($conn,$sql);
$data = array();
while($row=sqlsrv_fetch_array($result)) {
$data[] = $row;
}
foreach($data as $p) {
echo $p['Name']."<br>";
}
sqlsrv_close($conn);
echo "<br> Done <br>";
echo date("Y-m-d h:i:s");
?>
php自動產生隨機密碼
该算法主要用到了两个函数,
mt_rand ( int $min , int $max )
函数用于生成随机整数,其中 $min – $max 为 ASCII 码的范围,这里取 33 -126 ,可以根据需要调整范围,如ASCII码表中 97 – 122 位对应 a – z 的英文字母,具体可参考
ASCII码表
;
chr ( int $ascii )
函数用于将对应整数 $ascii 转换成对应的字符
function create_password($pw_length = 8)
{
$randpwd = '';
for ($i = 0; $i < $pw_length; $i++)
{
$randpwd .= chr(mt_rand(33, 126));
}
return $randpwd;
}
// 调用该函数,传递长度参数$pw_length = 6
echo create_password(6);
php防止sql注入函数-discuz版本
$magic_quotes_gpc = get_magic_quotes_gpc();
@extract(daddslashes($_COOKIE));
@extract(daddslashes($_POST));
@extract(daddslashes($_GET));
if(!$magic_quotes_gpc) {
$_FILES = daddslashes($_FILES);
}
function daddslashes($string, $force = 0) {
if(!$GLOBALS['magic_quotes_gpc'] || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
2011-01-19
JS判斷IE瀏覽器最簡短方法
<script type=
'text/javascript'
>
// Option from Dean Edwards:
var
ie =
/*@cc_on!@*/
false
;
// Use the commented line:
var
ie
//@cc_on=1;
// Variation (shorter variable):
var
ie =
'\v'
==
'v'
;
/ / Option to Gareth Hayes (former record-holder):
var
ie = !+
"\v1"
;
</script>
2010-12-29
PHP API調用BING翻譯
資料來源:
http://www.kalvin.cn/study/php-api-call-bing-translation-results.html
<?php
echo
bingtrans
(
'大家好,欢迎光临我的博客!'
);
//return: Hello, and welcome to my blog!
function
bingtrans
(
$str
=
''
,
$in
=
'zh-CHS'
,
$to
=
'en'
,
$api
=
'C2D5477B17DD7DCB1391E6B4D3222F2DB8AFAE7D'
) {
if (empty(
$str
)) {
return
false
;
}
$url
=
"http://api.microsofttranslator.com/v2/Http.svc/Translate?appId="
.
$api
.
"&text="
.
urlencode
(
$str
) .
"&from="
.
$in
.
"&to="
.
$to
;
if (
function_exists
(
'curl_init'
)) {
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
$res
=
curl_exec
(
$curl
);
} else {
$res
= @
file_get_contents
(
$url
);
}
preg_match
(
"~<string([^><]*?)>([\s\S]*?)<\/string>~i"
,
$res
,
$ostr
);
if (empty(
$ostr
[
2
])) {
return
false
;
} else {
return
htmlspecialchars_decode
(
$ostr
[
2
]);
}
}
?>
較新的文章
較舊的文章
首頁