dongwei8440 2015-08-26 05:01 采纳率: 100%
浏览 97
已采纳

PHP Captcha - 文本不显示但某些Web浏览器的背景

I encounter PHP Captcha is not displaying text to certain web browser.

I tried it on my desktop using Firefox and IE, it was able to work. When I tried like other party desktop or mobile devices, it did not display the text in the captcha.

At first, I thought the reason was because the font does not exist inside cPanel and causing the font not to display. Therefore, I uploaded two different fonts and try.

  • arial.ttf
  • NotoSans.ttf

But the same problem occurred.

This is how my code and File Manager look like. Please let me know if you need further detail information.

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

Update Solution Found

It is because HTTP > HTTPS issue.

Aside from the technical aspects of how Transport Layer Security works, the other facet of securely exchanging data lies in how well we apply that security. For example, if we allow a user to submit an application’s login form data over HTTP we must then accept that an MitM is completely capable of intercepting that data and recording the user’s login data for future use. If we allow pages loaded over HTTPS to, in turn, load non-HTTPS resources then we must accept that a MitM has a vehicle with which to inject Cross-Site Scripting attacks to turn the user’s browser into a pre-programmed weapon that will operate over the browser’s HTTPS connection tranparently.

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

  • 写回答

2条回答 默认 最新

  • drll42469 2015-08-26 06:15
    关注
    @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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”