dongzenglin8292 2012-04-13 20:15
浏览 41
已采纳

PHP验证码使用纯文本

It's my first time posting here as it's also the first time I've decided to build a site from scratch for myself. I'm creating a contact page with a basic captcha script. For reasons you might think are crazy, I want to display the captcha as text. I decided against png as the (anti)aliasing was pretty bad with a transparent background and I don't think my site is going to cause too much unwanted attention yet.

Here is my captcha.php

<?php 

session_start();

$characters_on_image = 4;

$possible_letters = '0123456789';

$code = '';

$i = 0;
while ($i < $characters_on_image) { 
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}

echo $code;


header('Content-Type: text/plain');

$_SESSION['code'] = $code;
?>

The problem I'm having is that if I use <?php print $_SESSION['code']; ?> it will print the previous code. My programming is pretty ropey and I was wondering if there is a way to show the current generated code in a <label> tag?

  • 写回答

2条回答 默认 最新

  • dtiu94034 2012-04-14 10:31
    关注

    You could also output Unicode characters that look like regular ones (but aren't) and ask users to repeat them. The Cyrillic alphabet has many characters that look familiar to Latin ones, but are encoded differently:

    А vs A    В vs B    Е vs E    Ѕ vs S    І vs I    К vs K
    М vs M    Н vs H    О vs O    Р vs P    Т vs T    Х vs X
    

    This would be pretty easy to crack, but easy to implement and easy for users to solve.

    (With respect to your code sample: skip the whole session thing and just echo the CAPTCHA from your captcha.php file. Make sure to include a hash of the solution.)

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

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接