【问题标题】:captcha in php codeigniter showing fatal errorphp codeigniter中的验证码显示致命错误
【发布时间】:2020-05-12 22:06:54
【问题描述】:

我对 codeigniter 完全陌生,我使用在线教程为我在 codeigniter 中的登录表单创建了验证码。加载登录页面时出现以下错误:

> 致命错误:在

中调用未定义的函数 base_url()
    $config = array(
        'img_path'      => 'captcha_images/',
        'img_url'       => base_url().'captcha_images/',
        'img_width'     => '150',
        'img_height'    => 50,
        'word_length'   => 8,
        'font_size'     => 16
    );
    $captcha = create_captcha($config);


i dont have any folder named 'captcha_images', all i have is a controller for captcha,config and the view in login. As am new to this, is it because i dont have a folder or i didnt call any library? please help me with this. thanks in advance

【问题讨论】:

  • 您是否在配置文件中定义了 base_url?
  • @sauhardnc,是的

标签: php codeigniter config captcha


【解决方案1】:

转到 application/config/autoload.php 在下面写下这一行(您将在第 90 行找到 codeigniter 不错的文档) $autoload['helper'] = array('url');

这将自动加载 url 助手。 base_url() function is defined in url helper

您可以为特定控制器手动加载它

在控制器构造函数中写入此行$this->load->helper('url'); 或

Controller action function

更多关于base_url的信息click

Create CAPTCHA in codeigniter

【讨论】:

  • 如果是,您定义了任何 base_url() 函数,请注释掉该函数。重启服务器。这是初学者的常见问题。您是否在 application/config/config.php 设置了您的基本网址?
  • 是的,我在 config.php 中设置了基本 url。我的自动加载 php 中有这个 $autoload['helper'] = array('html','form','url','language','date','string','security','globalfunctions','验证码');
  • 当我添加验证码时,这个问题来了
  • 我已经添加了一个codeigniter CAPTCHA创建官方文档链接跟随这个。
  • 虽然 @jobayersozib 为您指明了正确的方向,但如今,实施某种程度的 Google 的 reCAPTCHA 更加用户友好、更安全、更容易。你考虑过吗? Codeigniter 的 CAPTCHA 库需要您进行更多处理(需要 GD、数据库、加载 truetype 字体等……而生成的验证码对于有动机的攻击者来说很容易破解)。
猜你喜欢
  • 1970-01-01
  • 2016-12-11
  • 1970-01-01
  • 2017-10-13
  • 1970-01-01
  • 2017-01-25
  • 1970-01-01
  • 2014-02-20
  • 1970-01-01
相关资源
最近更新 更多