PHP SMARTY 樣板引擎
//檢查並傳回欲拿到資料使用的變數
//$title = '' 則非必填
function db_CleanVars($var, $title = '', $filter = '')
{
global $db;
#寫入資料庫過濾
$var = $db->real_escape_string($var);
if($title){
if($var === "")redirect_header(WEB_URL, 3000, $title . '為必填!');
}
if ($filter) {
$var = filter_var($var, $filter);
if (!$var) {
redirect_header(WEB_URL, 3000, "不合法的{$title}");
}
}
return $var;
}