dongzenglin8292 2012-04-13 12: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 02: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部