帳號登錄
帳號:
密碼:
記住我 | 忘記密碼 | 帳號註冊
網站導覽
模組開發 : Xoops Security Class
作者 elie 於 2010年08月24日 20:22:07 (6612 次閱讀)

原始出處 http://www.xoops.org/modules/mediawiki/index.php/Xoops_Security_Class

 

XoopsSecurity 類別的功能是產生一個token 以確保頁面是由網站送出,而不是一個潛在XSS (cross-site scripting)攻擊。

不使用表單欄位或 HTML 使用 Xoops Token

表單的話使用 AddElement 函式:

$form->AddElement(new XoopsFormHiddenToken());

樣版中或直接是 HTML,先使用取得 token 的方式產生 HTML:

$html = $GLOBALS['xoopsSecurity']->getTokenHTML();

上面的範例會產生一個 HTML <input> 項目像:

<input type='hidden' name='XOOPS_TOKEN_REQUEST' id='XOOPS_TOKEN_REQUEST' value='9c87534e1fec743d0a985740a7ec927d' />

你可以將這個 <input> 項目用指定給Smarty 變數的方式指定給樣版,方式是:

$xoopTpl->assign('token', $html);

然後將 Smarty 變數 <{$token}> 放在HTML 樣版內。

驗證 token 的方式是將以下的程式碼放在處理表單資料的程式中:

if ($GLOBALS['xoopsSecurity']->check()) {

 // success path

} else {

 // fails path

}


可列印模式 轉寄給朋友

The XOOPS organisation ("XOOPS") is committed to protecting the privacy of users of the XOOPS.org sites.
The website used Ver.2.4.5 POWERED BY XOOPS PROJECT.