<?php
    session_start();
    header("Content-type = image/png");
    if(isset($_SESSION['my_captcha'])){
        unset($_SESSION['my_captcha']);
    }

    $string1="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    $string2="1234567890";
    $string = $string1.$string2;
    $string = str_shuffle($string);
    $random_text = substr($string,0,6);

    $_SESSION['my_captcha'] = $random_text;
    $im = @ImageCreate(70,35)
    or die("cannot intialize new GD image stream");

    $background_color = ImageColorAllocate($im,235, 235, 235);
    $text_color = ImageColorAllocate($im,51,51,255);

    ImageString($im,15,8,10,$_SESSION['my_captcha'],$text_color);
    ImagePng($im);
    imagedestroy($im);

?>