【问题标题】:Auto delete captcha image CI自动删除验证码图像 CI
【发布时间】:2012-01-28 08:13:39
【问题描述】:

我正在使用 CodeIgniter 的验证码助手为注册用户生成验证码图像。我有这样的价值:

$vals = array(
        'word' => $rand_word,
        'img_path' => 'resources/captcha/',
        'img_url' => 'http://localhost/fitinline/resources/captcha/',
        'font_path' => './path/to/fonts/texb.ttf',
        'img_width' => 150,
        'img_height' => 40,
        'expiration' => 7200
    );

当我使用create_captcha($vals) 函数生成验证码时,验证码图像自动保存到“img_path”。有一个到期索引,我将默认设置为 2 小时(7200)。但是两个多小时后,我检查了'img_path'中的图像,图像仍然保存在上面。是否有任何缺少的配置来启用自动删除那些验证码图像或什么,。?
谢谢

【问题讨论】:

    标签: codeigniter captcha


    【解决方案1】:
    /*Add script to delete all captcha file*/
    
    $files = glob('./captcha/*'); // get all file names
    foreach($files as $file)
    { 
      // iterate files
      if(is_file($file))
        unlink($file); // delete file
    }
    

    【讨论】:

      【解决方案2】:

      基于 CI 文档:

      $vals = array(
          'word'   => 'Random word',
          'img_path'   => './captcha/',
          'img_url'    => 'http://example.com/captcha/',
          'font_path'  => './path/to/fonts/texb.ttf',
          'img_width'  => '150',
          'img_height' => 30,
          'expiration' => 7200
          );
      

      “过期”(以秒为单位)表示图像将在验证码文件夹中保留多长时间后才会被删除。默认为两小时。

      【讨论】:

        【解决方案3】:

        如果没有 cron,图像将无法在过期后自行删除。 但是,当有人触发验证码助手时,他会检查是否有任何不应该存在的图像并将其删除。

        假设您已注册验证码。我正在创建新帐户。还创建了具有 7200 到期时间的新验证码。超过 7200 之后,您打开带有验证码图像的文件夹,并且图片仍然存在。第二天别人正在创建新帐户,新的验证码被创建。但是在那一刻,助手看到有图像不应该存在(从昨天开始)并且他将其删除。

        所以您不必担心,验证码文件夹中有图像。一旦创建了一些新的验证码并且它们的时间到期,它们应该被删除。您可以在 captcha_helper 文件中查看部分代码:

            // -----------------------------------
            // Remove old images
            // -----------------------------------
        

        如果您不能等到助手被触发,您应该创建用于删除图像的脚本并将其添加到 cron。

        【讨论】:

          【解决方案4】:

          验证码是否正常工作? (您检查过目录权限吗?)

          对此我不确定,但请尝试按照 CI 指南中的说明保存 create_captcha() 数据库的结果。

          CREATE TABLE captcha (
           captcha_id bigint(13) unsigned NOT NULL auto_increment,
           captcha_time int(10) unsigned NOT NULL,
           ip_address varchar(16) default '0' NOT NULL,
           word varchar(20) NOT NULL,
           PRIMARY KEY `captcha_id` (`captcha_id`),
           KEY `word` (`word`)
          );
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2015-04-08
            • 2011-12-15
            • 1970-01-01
            • 2011-12-20
            • 1970-01-01
            • 2020-01-10
            • 1970-01-01
            相关资源
            最近更新 更多