GD库的配置
1、windows下
   修改php.ini文件,去掉extension=php_gd2.dll 前面的分号。
   修改extension_dir = "c:/kaosco/php2/extensions" 为动态库所在目录
2、Linux、unix下
   需要 重新编译php。

解决方案 »

  1.   

    再问!!!!
    <?php
    //随机字符串函数
    function my_random_password($length)
    {
        $result = "";
        $string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        for ($i = 0 ; $i < $length ; $i++)
        {
            $result .= $string[mt_rand(0 , strlen($string) - 1)];
        }
        return $result;
    }
    //判断是否需要加载相应的gd库
    if (!extension_loaded('gd'))
    {
        if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
        {
            dl('php_gd2.dll');
        }
        else
        {
            dl('gd2.so');
        }
    }
    ?>
    <?
    //告诉浏览器发送的是png图片
    header ("content-type: image/png");
    //图像长宽初始化
    $image_x = 100;
    $image_y = 40;
    //创建图片
    $image = imagecreate($image_x , $image_y);
    //定义背景色
    $background_color = imagecolorallocate($image , 0xFF , 0xFF , 0xFF);
    //定义所需要的颜色
    $black_color = imagecolorallocate($image , 0x00 , 0x00 , 0x00);
    $gray_color  = imagecolorallocate($image , 0xcc , 0xcc , 0xcc);
    //循环生成雪花点
    for ($i = 0 ; $i < 1000 ; $i++)
    {
        imagesetpixel($image , mt_rand(0 , $image_x) , mt_rand(0 , $image_y) , $gray_color);
    }
    //把随机字符串输入图片
    imagestring($image , 4 , 20 , 12 , my_random_password(8) , $black_color);
    //生成矩形边框
    imagerectangle($image , 0 , 0 , $image_x - 1 , $image_y - 1 , $black_color);
    //生成图片
    imagepng($image);
    //释放与$image关联的内存
    imagedestroy($image);
    ?>这样可以生成一个验证码!并可以显示!
    但是在?>  <? 中间加入
    <form action=gd.php method=POST>
    <table>
    请输入验证码:<input type=text name=authinput style="width: 80px"><br>
    <input type=submit name="验证" value="提交验证码">
    </table>
    </form>
    则就报错!
    验证码输出为乱码!
    急呀!