【问题标题】:PHP Captcha - Text Not Showing But Background to Certain Web BrowserPHP Captcha - 文本不显示,但某些 Web 浏览器的背景
【发布时间】:2015-11-20 00:04:51
【问题描述】:

我遇到 PHP Captcha 没有向某些 Web 浏览器显示文本。

我在我的桌面上使用 Firefox 和 IE 进行了尝试,它能够工作。当我像其他方桌面或移动设备一样尝试时,它没有显示验证码中的文字。

一开始我以为是因为cPanel里面没有字体,导致字体不显示。因此,我上传了两种不同的字体并尝试。

  • arial.ttf
  • NotoSans.ttf

但同样的问题发生了。

这就是我的代码和文件管理器的样子。如果您需要更多详细信息,请告诉我。

session_start();
$captcha_answer = $_SESSION['captcha_answer'];
$handle = ImageCreate (100, 40) or die ("Cannot Create image"); 
$bg_color = ImageColorAllocate ($handle, 176, 26, 72); //green
$font_color = ImageColorAllocate ($handle, 255, 255, 255);
$font = 'NotoSans.ttf';

imagettftext($handle, 20, 0, 10, 20, $bg_color, $font, $captcha_answer);
imagettftext($handle, 20, 7, 13, 32, $font_color, $font, $captcha_answer);

ImagePng($handle);

cPanel File Manager - Click Here to View

找到更新解决方案

这是因为 HTTP > HTTPS 问题。

除了传输层安全性如何工作的技术方面之外,安全交换数据的另一个方面在于我们应用该安全性的程度。例如,如果我们允许用户通过 HTTP 提交应用程序的登录表单数据,那么我们必须接受 MitM 完全能够拦截该数据并记录用户的登录数据以供将来使用。如果我们允许通过 HTTPS 加载的页面反过来加载非 HTTPS 资源,那么我们必须接受 MitM 有一个工具可以注入跨站点脚本攻击,从而将用户的浏览器变成可以运行的预编程武器透明地通过浏览器的 HTTPS 连接。

来源:http://phpsecurity.readthedocs.org/en/latest/Transport-Layer-Security-(HTTPS-SSL-and-TLS).html

【问题讨论】:

  • $captcha_answer 有什么价值吗?呼应它,看看它是否有任何价值。
  • @Kane:您想提供有关解决方案的更多详细信息吗?你提到了问题的原因,但你没有说你为解决它做了什么。我只是出于好奇想知道您做了什么,但我想这对将来遇到同样问题的人也很有用。
  • @Master_ex,如果链接是example.com 而不是example.com,则基本上不会加载captcha.php。我发现 http://[www.example.com/ 出于安全目的可能会阻止它。我编辑了答案。请快速阅读。如果我错了,请纠正我。
  • @ShaileshKatarmal,是的,我可以回应 $captcha_answer。但目前还不是$captcha_answer,我认为是协议问题。

标签: php captcha


【解决方案1】:

尝试为 png 图像设置正确的标题:

session_start();
$captcha_answer = $_SESSION['captcha_answer'];
$handle = ImageCreate (100, 40) or die ("Cannot Create image"); 
$bg_color = ImageColorAllocate ($handle, 176, 26, 72); //green
$font_color = ImageColorAllocate ($handle, 255, 255, 255);
$font = 'NotoSans.ttf';

imagettftext($handle, 20, 0, 10, 20, $bg_color, $font, $captcha_answer);
imagettftext($handle, 20, 7, 13, 32, $font_color, $font, $captcha_answer);

header('Content-Type: image/png');
ImagePng($handle); 

此外,我建议设置标题以便浏览器不缓存图像,以防图像总是动态生成。请参阅this 回答,了解如何实现。

【讨论】:

    【解决方案2】:
    @session_start();
    $_SESSION['captcha_answer'] = "hello";
    $captcha_answer = $_SESSION['captcha_answer'];
    $handle = ImageCreate (100, 40) or die ("Cannot Create image"); 
    $bg_color = ImageColorAllocate ($handle, 176, 26, 72); //green
    $font_color = ImageColorAllocate ($handle, 255, 255, 255);
    $font = 'font/monofont.ttf';  // your font path goes here....
    
    header('Content-Type: image/png');
    imagettftext($handle, 20, 0, 10, 20, $bg_color, $font, $captcha_answer);
    imagettftext($handle, 20, 7, 13, 32, $font_color, $font, $captcha_answer);
    
    ImagePng($handle);
    

    【讨论】:

      猜你喜欢
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 2011-06-22
      • 2010-11-01
      • 2010-10-17
      • 2017-03-07
      • 1970-01-01
      相关资源
      最近更新 更多