<?php
error_reporting(0);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: text/html;charset=gb2312");
include "../../include/cctvai.conn.php";
$ac=SafeRequest("ac", "get");
$op=SafeRequest("op", "get");
$id=SafeRequest("id", "get");
//生成验证码
if($ac == "seccode") {
    Header("Content-type:image/png");
    session_start(); //开启session;
    $authnum_session='';
    $str='1234567890';
    $l=strlen($str); //得到字串的长度; 
    for($i=1; $i <= 4; $i++) {
        $num=rand(0, $l-1);
        $authnum_session.=$str[$num];
    }
    $_SESSION["codes"]=$authnum_session;
    //session_register("authnum_session");
    srand((double) microtime()*1000000);
    $im=imagecreate(50, 20); //图片宽与高; 
    $black=ImageColorAllocate($im, 0, 0, 0);
    $white=ImageColorAllocate($im, 255, 255, 255);
    $gray=ImageColorAllocate($im, 200, 200, 200);
    imagefill($im, 68, 30, $gray);
    $li=ImageColorAllocate($im, 220, 220, 220);
    for($i=0; $i < 3; $i++) {
        imageline($im, rand(0, 30), rand(0, 21), rand(20, 40), rand(0, 21), $li);
    }
    imagestring($im, 5, 8, 2, $authnum_session, $white);
    for($i=0; $i < 90; $i++) {
        imagesetpixel($im, rand()%70, rand()%30, $gray);
    }
    ImagePNG($im);
    ImageDestroy($im);
} elseif($ac == "loginseccode") {
    Header("Content-type:image/png");
    session_start(); //开启session;
    $authnum_session='';
    $str='1234567890';
    $l=strlen($str); //得到字串的长度; 
    for($i=1; $i <= 4; $i++) {
        $num=rand(0, $l-1);
        $authnum_session.=$str[$num];
    }
    $_SESSION["codes"]=$authnum_session;
    //session_register("authnum_session");
    srand((double) microtime()*1000000);
    $im=imagecreate(100, 40); //图片宽与高; 
    $black=imagecolorallocate($im, 235, 236, 237);
    $white=ImageColorAllocate($im, 200, 120, 120);
    $gray=ImageColorAllocate($im, 255, 255, 255);
    imagefill($im, 110, 45, $gray);
    $li=ImageColorAllocate($im, 120, 120, 120);
    for($i=0; $i < 3; $i++) {
        imageline($im, rand(0, 30), rand(0, 21), rand(20, 40), rand(0, 21), $li);
    }
    imagestring($im, 5, 33, 12, $authnum_session, $white);
    for($i=0; $i < 90; $i++) {
        imagesetpixel($im, rand()%70, rand()%30, $gray);
    }
    ImagePNG($im);
    ImageDestroy($im);
}
?>