2011-02-03 22 views
0

私は実用的なcakephpブックからAscii Captchaを使用しました。しかし、私はユーザー情報とキャプチャコードを同時に検証することはできません。以下は私のコードcaptcha登録フォーム

**In user controller ** 

function check() { 
     if (!empty($this->data['User']['secure'])) { 
      if ($this->data['User']['secure'] == $this->Session->read('string')) { 
       $this->Session->setFlash(__('You have entered the right characters', true)); 
      } else { 
       $this->Session->setFlash(__('You have entered the wrong characters. Please, try again.', true)); 
      } 
     } else { 
      $this->Session->setFlash(__('You need to enter the correct characters. Please, try again.', true)); 
     } 
    } 

function register() { 

     $captcha = $this->AsciiCaptcha->getCaptcha(); 

     $string = implode("", array_keys($captcha)); 
     $this->set(compact('captcha', 'string')); 
     $this->Session->write('string', $string); 

     if (!empty($this->data)) { 
      $this->User->create(); 
      if ($this->User->save($this->data)) { 

       $data = $this->User->read(); 
       $this->Auth->login($data); 
       $aro = new Aro(); 
       $parent = $aro->findByAlias($this->User->find('count') > 1 ? 'User' : 'Admin'); 
       $aro->create(); 
       $aro->save(array(
        'model' => 'User', 
        'foreign_key' => $this->User->id, 
        'parent_id' => $parent['Aro']['id'], 
        'alias' => 'User::' . $this->User->id 
       )); 
       $this->Session->setFlash(__('The user has been saved', true)); 
       $this->Auth->logout(); 
       $this->redirect('login'); 
      } else { 
       $this->Session->setFlash(__('The user could not be saved. Please, try again.', true)); 
      } 
     } 

     $groups = $this->User->Group->find('list'); 
     $this->set(compact('groups')); 
    } 

私は、ユーザー情報が正しいとコードが一致しているかnot.Butは、任意の解決策を見つけたことができないかどうかを確認するために多くの方法を使用しています。助けてください。

+0

セッションの方法は非常にユーザーフレンドリーではないことに注意してください - http://www.dereuromark.de/2010/08/09/how-to-implement-captchas-properly/ – mark

答えて

0

あなたは... = $グループの後に/直前、法の下にその検証に使用される前に、あなたは以上のセッションでものを書いている

$captcha = $this->AsciiCaptcha->getCaptcha(); 
$string = implode("", array_keys($captcha)); 
$this->set(compact('captcha', 'string')); 
$this->Session->write('string', $string); 

これを持っている必要がありますように見えますそれは常に間違っています。