ZF1_smarty_session_captcha

来源:互联网 发布:剑灵捏脸数据怎么用 编辑:程序博客网 时间:2024/06/15 23:10

<1>.图像因其本身有错无法访问。
这里我并没有使用perl的captcha来生成图像,而是面向对象了一个之前用过的代码。
1.GD必须采用IE来调试。这样才能显示出详细错误来。

2.禁止调用视图 
  // disable auto-rendering since we're outputting an image
        $this->_helper->viewRenderer->setNoRender();

3.ZF的session()的用法
 $session = new Zend_Session_Namespace('captcha');
        // check for existing phrase in session
        $phrase = null;
        if (isset($session->phrase) && strlen($session->phrase) > 0)
               {    
          $phrase = $session->phrase;
              }
        // write the phrase to session
        else
          {
          $phrase = $this->getRandomCode();
          $session->phrase =$phrase;
          }

3.获取表单值并验证
     $session = new Zend_Session_Namespace('captcha');
            //要使用$request->getPost('captcha'),必须继承Zend_Controller_Action类
            $this->captcha = $this->sanitize($request->getPost('captcha'));


            if ($this->captcha != $session->phrase)
                $this->addError('captcha', 'Please enter the correct phrase');

            // if no errors have occurred, save the user
            if (!$this->hasError()) {
                $this->user->save();
                 unset($session->phrase);
            }

4.新的smarty用法
$smarty = new Smarty();//----------------------------------------------->getEngine(),在构造函数中创建一次
$smarty->template_dir = $config->path->templates;
$smarty->compile_dir = $config->paht->."/tmp/templates_c";
$name = "lbzhao";
$smarty->assign('news',$name);//---------------------------------------->$this->view->news = $name;
$smarty-display('news/index.tpl');//-------------------------------------->render();

//视图的调用
$this->_redirect(''/account/registerover'');
$this->_forward('register');

 

5.写SQL的用法

 

 

6.生成验证的代码

原创粉丝点击