dongtaihui5131 2014-04-18 00:13
浏览 73
已采纳

在受保护的目录中使用Securimage和securimage_show.php

I have a MVC app and I used composer to install securimage.

The directory layout is like so:

app/
     composer.json
     composer.lock
     vendor/
           ...
           dahpp/securimage (with securimage.php, securimage_show.php, etc).
public_html/
    .htaccess
     index.php (routing, bootstrapping, etc.)
     templates/
           contact.php

Nothing under app is publicly available. Since securimage_show.php is not accessible, I'm trying to put the captcha generation code in the contact.php template itself.

So in that template, I have this:

<?php
    session_start();
    $securimage = new Securimage(array('send_headers' => false));
?>

later in the HTML...

<img id="captcha" src="<?= $securimage->show() ?>" alt="CAPTCHA Image" />

The problem is when I do this, I get a bunch of question mark gibberish (?�), like there's an encoding issue or something. If I set send_headers to true, I get an error: "Failed to generate captcha image, content has already been output. This is most likely due to misconfiguration or a PHP error was sent to the browser."

Using getCaptchaHtml() doesn't work, either. The image path that it tries to generate goes appends the absolute path on the machine to the host (http://www.example.com/var/www/app/vendor/dahpp/securimage).

What does work is a symlink in the public_html directory to the protected app directory. In other words, if I create a symlink called securimage_show.php and point it to the real file under app/vendor/dahpp/securimage, and set the img source to it:

<img id="captcha" src="securimage_show.php" alt="CAPTCHA Image" />

However, this doesn't seem as clean as using the official methods available. Is there a setting I'm missing somewhere or am I stuck using the symlink approach?

  • 写回答

2条回答 默认 最新

  • dtqie02844 2014-04-18 04:04
    关注

    In order to show the captcha image, you must copy securimage_show.php to a publicly accessible folder so the image generation works (or create a symlink called securimage_show.php and point it to the install folder).

    Then, since securimage.php is in a different path than securimage_show.php, you need to pass an option to getCaptchaHtml() so it uses the correct src attribute in the <img> tag.

    $options = array('securimage_path' => '/images'); // <= change this path
    echo Securimage::getCaptchaHtml($options);
    

    The reason you get gibberish when you put $securimage->show() in the img tag is because it returns binary data representing the image, not data that can be passed to an img tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作