tp5框架原理詳解 TP5框架安全機制例項分析

2021-10-13 10:36:57 字數 1209 閱讀 3957

防止sql注入

1、查詢條件盡量使用陣列方式,具體如下:

$wheres = array();

$wheres['account'] = $account;

$wheres['password'] = $password;

$user->where($wheres)->find();

2、如果必須使用字串,建議使用預處理機制,具體如下:

$user = d('userinfo');

$user->where('account="%s" andpassword="%s"',array($account,$password))->find();

3、可以使用pdo方式(繫結引數),因為這裡未使用pdo,所以不羅列,感興趣的可自行查詢相關資料。

表單合法性檢測

1、配置insertfields和updatefields屬性

class userinfomodelextends model {

// 資料表名字

protected $turetablename ='user';

// 配置插入和修改的字段匹配設定(針對表單)

protected $insertfields =array('name','***','age');

protected $updatefields =array('nickname','mobile');

上面的定義之後,當我們使用了create方法建立資料物件後,再使用add方法插入資料時,只會插入上面配置的幾個欄位的值(更新類同),具體如下:

// 使用者註冊(示意性介面:插入)

public function register() {

// 使用model的create函式更安全

$user= d('userinfo');

$user->create();

$id= $user->add();

if($id) {

$result= $user->where('id=%d',array($id))->find();

echo json_encode($result);

2、使用field方法直接處理

// 插入

m('user')->field('name,***,age')->create();

// 更新

m('user')->field('nickname,mobile')->create();

TP5框架低版本漏洞

漏洞1 設定預設過濾機制 request filter config default filter 當前模組路徑 modulepath module module.ds 是否自動轉換控制器和操作名 convert is bool convert convert config url convert ...

TP5 框架 實現無限級分類

首先我們在模型中的 use think model class cate extends model 建立方法 data引數是資料庫所有資料 pid引數是資料庫pid le引數是為了區分顯示級別的 public function sort data,pid 0,level 0 將最後的內容輸出返回 ...

TP5常量參考

ext 類庫檔案字尾 php think version 框架版本號ds 當前系統的目錄分隔符 think path 框架系統目錄 root path 框架應用根目錄 lib path 系統類庫目錄 預設為 think path.library core path 系統核心類庫目錄 預設為 lib ...