| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 792 人关注过本帖
标题:下面是验证码的代码,怎样得到验证码的值??? 是$_SESSION['code']吗? 但是输 ...
只看楼主 加入收藏
赤那
Rank: 3Rank: 3
来 自:广东
等 级:论坛游侠
威 望:1
帖 子:127
专家分:178
注 册:2010-3-1
结帖率:80%
收藏
已结贴  问题点数:0 回复次数:1 
下面是验证码的代码,怎样得到验证码的值??? 是$_SESSION['code']吗? 但是输出是空的
//code.php
<?PHP
error_reporting(0);
session_start();
session_register('code');
$_SESSION['code'] = '';
$width = '58';//图片宽
$height = '25';//图片高
/*for ($i=0; $i<4; $i++) {
    $tmptext=rand(0, 9);
    $code .= $tmptext;
}*/
function createRandomStr($strLen)//随机生成验证码
 {
  list($usec, $sec) = explode(' ', microtime());
        (float) $sec + ((float) $usec * 100000);
        
  $number = '';
  $number_len = $strLen;
  $stuff = '123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';//附加码显示范围ABCDEFGHIJKLMNOPQRSTUVWXYZ
  $stuff_len = strlen($stuff) - 1;
  for ($i = 0; $i < $number_len; $i++) {
  $number .= substr($stuff, mt_rand(0, $stuff_len), 1);
  }
  return $number;
}
$code=createRandomStr(4);//得到验证码4位数
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");

if(function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') && function_exists('imagecolorallocate') && function_exists('imagesetpixel') && function_exists('imagechar') && function_exists('imagecreatefromgif') && function_exists('imagepng')) {

    $im = imagecreate($width, $height);
    $backgroundcolor = imagecolorallocate ($im, 255, 255, 255);

    $numorder = array(1, 2, 3, 4);
    shuffle($numorder);

    $numorder = array_flip($numorder);
//print_r ($numorder);
    for($i = 1; $i <= 4; $i++) {
        $x = $numorder[$i] * 13 + mt_rand(0, 4) - 2;
        $y = mt_rand(0, 3);
        $text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255));
        imagechar($im, 5, $x + 5, $y + 3, $code[$numorder[$i]], $text_color);
        //echo $code[$numorder[$i]];
        fwrite($ss, $code[$numorder[$i]]);
    }
    $linenums = mt_rand(10, 32);
    /*for($i=0; $i <= $linenums; $i++) {
        $linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        $linex = mt_rand(0, $width);
        $liney = mt_rand(0, $height);
        imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
    }

    for($i=0; $i <= 40; $i++) {
        $pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
        imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointcolor);
    }*/////加入干扰象素

    $bordercolor = imagecolorallocate($im , 150, 150, 150);
    imagerectangle($im, 0, 0, $width-1, $height-1, $bordercolor);

    header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im);

}

?>


//show.php
<?php
$_SESSION['code'];//空的
?>
搜索更多相关主题的帖子: function 验证码 图片 
2011-03-19 23:50
gupiao175
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
收藏
得分:5 
//show.php
<?php
$_SESSION['code'];//空的
?>
显示不是这么做的:
改为:
//show.php
<?php
session_start();
echo $_SESSION['code'];//空的
?>
前提是code.php里有给$_SESSION['code']赋值!show.php方能显示!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2011-03-24 14:10
快速回复:下面是验证码的代码,怎样得到验证码的值??? 是$_SESSION['code']吗? 但 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025764 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved