<? session_start( ); $_SESSION['code'] = ""; //generate code $string = substr( crypt( rand( ) ), -5 ); //unwanted characters $junk = array('.' , ',' , '/' , '' , '`' , ';' , '[' , ']' , '-', '_', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '='); //strip unwanted $string = str_replace( $junk, '', $string ); //image background $im = imagecreatefrompng( "http://www.yoursite.com/path/to/background_image.png" ); $orange = imagecolorallocate( $im, rand(1,100), rand(1,100), rand(1,100) ); $half = imagesx( $im ) / 2; $start = rand( 10, $half / 1.5 ); $y = imagesy( $im ) / 2; $pos = $start; for ( $i = 0; $i < strlen( $string ); $i++ ) { imagestring( $im, 100, $pos, $y, $string[$i], $orange ); $pos += rand(11,15); $y += 5-rand(0,10); } //image cover $cov = imagecreatefrompng( "http://www.yoursite.com/path/to/cover_image.png" ); imagecopyresampled( $im, $cov, 0, 0, 0, 0, 300, 100, 300, 100 ); header('Content-type: image/png'); imagepng($im); imagedestroy($im); $_SESSION['code'] = $string; session_write_close(); ?>