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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路