ãã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¯ã³
ãã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¯ã³ã®çæï¼ãã§ãã¯æ©è½ãå®è£ ãã¦ã¿ãããã®æ©è½ã¯Moony 0.8.1ã§è¿½å ãããäºå®ã
Moony_Tokenã¨ããã¯ã©ã¹ãæ°ãã«è¿½å ãã¡ã½ããã2ã¤ç¨æããã
- generate(&$session, &$response)
- ã»ãã·ã§ã³ãéå§ããã¦ããå ´å
- ã»ãã·ã§ã³ãéå§ããã¦ããªãå ´å
- ä½ãããã«falseãè¿ã
- check(&$request)
- ã»ãã·ã§ã³ãéå§ããã¦ããªãå ´å
- ç¡æ¡ä»¶ã«falseãè¿ã
- ãªã¯ã¨ã¹ããã©ã¡ã¼ã¿ã¨ãã¦ãã¼ã¯ã³ãéä¿¡ããã¦ããªãå ´å
- ç¡æ¡ä»¶ã«falseãè¿ã
- ã»ãã·ã§ã³ãéå§ããã¦ãã¦ããã¼ã¯ã³ãéä¿¡ããã¦ããå ´å
- ã»ãã·ã§ã³ããä¿åãã¦ããããã¼ã¯ã³å¤ãåå¾
- ç´ã¡ã«ã»ãã·ã§ã³ãããã¼ã¯ã³å¤ãåé¤
- ãªã¯ã¨ã¹ããã©ã¡ã¼ã¿ã¨ãã¦éä¿¡ããã¦ãããã¼ã¯ã³å¤ã¨ä¿åãã¦ãããå¤ãæ¯è¼
- åè´ããå ´åtrueãè¿ã
- åè´ããªãå ´åfalseãè¿ã
- ã»ãã·ã§ã³ãéå§ããã¦ããªãå ´å
Moony_Config.phpã«è¨å®è¿½å
define('MOONY_TRANSACTION_TOKEN_NAME', 'transaction_token');
Moony_Tokenã®å®è£ :
class Moony_Token { function generate(&$request, &$response) { $session = $request->getSession(); if ($session->hasStarted()) { $token = md5(uniqid(rand(), true)); $session->set(MOONY_TRANSACTION_TOKEN_NAME, $token); $response->set(MOONY_TRANSACTION_TOKEN_NAME, $token); return true; } return false; } function check(&$request) { $session = $request->getSession(); if (!$session->hasStarted()) { return false; } if (!$request->exists(MOONY_TRANSACTION_TOKEN_NAME)) { return false; } $saved = $session->get(MOONY_TRANSACTION_TOKEN_NAME); $session->remove(MOONY_TRANSACTION_TOKEN_NAME); if ($request->get(MOONY_TRANSACTION_TOKEN_NAME) == $saved) { return true; } return false; } }
ãã©ã¼ã ã®è¨è¿°ä¾:
<form> <input type="hidden" name="transaction_token" value="{$transaction_token}" /> </form>
ã¢ã¯ã·ã§ã³ã¯ã©ã¹ã§ãã§ãã¯ãè¡ãå ´å:
class FooAction extends Moony_Action { function execute($request, $response) { if (Moony_Token::check($request)) { // check success } else { // check failure } } }
â»2006-02-28ã«ä¸é¨å 容ãä¿®æ£ãã¾ããã