<?php
header ( 'content-type:p_w_picpath/png' );
$dotsize = 50;
$linesize = 10;
$width = 130;
$height = 30;
$p_w_picpath = p_w_picpathcreate ( $width, $height );
$bgcolor = p_w_picpathcolorallocate ( $p_w_picpath, 251, 251, 251 );
for($i = 0; $i < $dotsize; $i ++) {
$color = p_w_picpathcolorallocate ( $p_w_picpath, rand ( 1, 255 ), rand ( 1, 255 ), rand ( 1, 255 ) );
$s = rand ( 2, 5 );
p_w_picpathfilledellipse ( $p_w_picpath, rand ( 0, $width ), rand ( 0, $height ), $s, $s, $color );
}
for($i = 0; $i <= $linesize; $i ++) {

$color = p_w_picpathcolorallocate ( $p_w_picpath, rand ( 1, 255 ), rand ( 1, 255 ), rand ( 1, 255 ) );
p_w_picpathline ( $p_w_picpath, 0, rand ( 0, $height ), $width, rand ( 0, $height ), $color );
}

$textcolor = p_w_picpathcolorallocate ( $p_w_picpath, rand ( 1, 255 ), rand ( 1, 255 ), rand ( 1, 255 ) );
$font = "SIMLI.TTF";
$str = getStr ( 5 );
p_w_picpathttftext ( $p_w_picpath, 20, 0, 3, 20, $textcolor, $font, iconv ( 'gbk', 'utf-8', $str ) );
p_w_picpathpng ( $p_w_picpath );
p_w_picpathdestroy ( $p_w_picpath );
function getStr($length = 4) {
$str = "abcdefghijklmnopqrstuvwxyz" . strtoupper ( "abcdefghijklmnopqrstuvwxyz" ) . "0123456789";
$s = "";
for($i = 0; $i < $length; $i ++) {
$s .= substr ( $str, rand ( 0, strlen ( $str ) - 1 ), 1 );
}
return $s;
}
另外新建一页做引用:
<img src="check.php" onclick="this.src='check.php?'+new Date()"/><br/>