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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度