你的$rand没有定义啊!楼主把代码改为:<?php
error_reporting(E_ALL);
$rand=0;
for ($i=0;$i<4;$i++)
{
        $rand.=dechex(rand(1,15));
}
$im= ImageCreateTrueColor(100, 30);
//设置颜色
$bg=ImageColorAllocate($im, 0, 0, 0);
$te=ImageColorAllocate($im, 255, 255, 255);
//把字符串写在图象左上角
ImageString ($im, 5,0,0,$rand,$te);
//输出图象
header ('Content-type: image/png');
ImagePng($im);
ImageDestroy($im);
?>这样就可以了。

解决方案 »

  1.   

    谢谢!不过有这条代码error_reporting(E_ALL);
    怎么不会报错呢??
      

  2.   


    呵呵,error_reporting(E_ALL);这个E_ALL是不包括E_NOTICE的。E_ALL的PHP官方定义:All errors and warnings。只有所有的Error和Warnings,没有Notice级别的。而,未定义变量属于Notice的。
      

  3.   

    error_reporting 包含 notice 吧 
    因为 header ('Content-type: image/png'); 有这句 所以不会显示notice信息了