2011-06-13

APACHE支援.htaccess

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

 修正為
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

2011-05-04

php 將數字補零 使用str_pad

http://tw2.php.net/str_pad
string str_pad ( string $input , int $pad_length [, string $pad_string = " " [, int $pad_type = STR_PAD_RIGHT ]] )


<?php
$input 
"Alien";
echo 
str_pad($input10);                      // produces "Alien     "echo str_pad($input10"-="STR_PAD_LEFT);  // produces "-=-=-Alien"echo str_pad($input10"_"STR_PAD_BOTH);   // produces "__Alien___"echo str_pad($input"___");               // produces "Alien_"?>

2011-05-03

js實現判斷來源

js實現判斷當前網址的來路如果不是指定的來路就跳轉到指定頁面

<script type="text/javascript"> 
if(self!=top){top.location=self.location;} 
var ref=document.referrer; 
var domains=new Array("jb51.net/","jb51.cn/","jb51.com.cn/"); 
var refpass=false; 
for(i=0;i<=domains.length;i++){if(ref.indexOf(domains[i])>0){refpass=true;break;}} 
if(ref==""){refpass=true} 
if(!refpass){window.location.href='http://www.jb51.net';} 
</script>

2011-04-26

PHP讀取EXCEL 2007 2003

一個功能強大的Excel函式庫,一般的讀寫都可以處理,且支援圖片插入。
官方網站:http://www.codeplex.com/PHPExcel/


/** PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';


if (!file_exists("05featuredemo.xlsx")) {
exit("Please run 05featuredemo.php first.\n");
}

echo date('H:i:s') . " Load from Excel2007 file\n";
$objPHPExcel = PHPExcel_IOFactory::load("05featuredemo.xlsx");

echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));


// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

// Echo done
echo date('H:i:s') . " Done writing files.\r\n";

PHP 使用 Apache WWW-Authenticate 認證身份

<?php
$user = '認證帳號';
$pw = '認證密碼';

if(!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_PW']=='') {
    Header("WWW-Authenticate: Basic realm=\"login\"");
    Header("HTTP/1.0 401 Unauthorized");
    die('認證失敗');
} else {
    if($_SERVER['PHP_AUTH_USER']!=$user || $_SERVER['PHP_AUTH_PW']!=$pw) {
        Header("WWW-Authenticate: Basic realm=\"login\"");
        Header("HTTP/1.0 401 Unauthorized");
        die('帳號或密碼錯誤');
    }
}

echo "認證成功";

json xss 防範

更改MIME文檔類型來防範。 測試的時候發現text/plain 、application/x-zip-compressed 是會被IE解析了。
 其他應該還是會有的,沒有一個一個測試。

header ( "Content-type: application/json" ) ; 

本文地址: http://www.woyigui.cn/2009/04/28/json-xss/

2011-04-25

mysql_num_rows VS COUNT 效率問題分析

一個直觀的對比 
測試數據: 
條數:139764條 
數據表大小:500M 

結果: 
fetch_num_rows 用時:35.272329092026 
count(*) 用時:0.071956872940063 

如果單純統計數量當然是count(*) 
fetch_num_rows必須遍歷數據庫以後才能得出效率低於count(*)

原文參考:http://jb51.net/article/26935.htm

2011-04-21

Mysql 文字轉日期排序

SELECT STR_TO_DATE(concat(AC_Month,'/', AC_Year + 1911), '%m/%Y') as dd,s. *
FROM tndg_activities_month AS m, tndg_activities_service AS s
WHERE s.A_SERIALNO = m.SERIALNO
AND s.MemberID = '??'
ORDER BY dd

解決javascript的window.close()在IE7會有提示的問題

<script language=javascript> 
window.opener=null
window.open("","_self"); window.close();
</script>

2011-04-18

Mysql數據庫like模糊查詢中文字段不準確的臨時解決辦法


select  *  from test.news where  binary title like  ' % s % '

字母區分大小寫
select  *  from test.news where  binary  ucase ( title )  like   ' % s % '