width =
$width
;
$this
->height =
$height
;
$this
->codeNum =
$codeNum
;
$this
->codeType =
$codeType
;
$this
->fontSize =
$fontSize
;
$this
->fontType =
$fontType
;
$this
->codeStr =
$codeStr
;
$this
->strNum =
strlen
(
$this
->codeStr)/3-1;
$this
->imageType =
$imageType
;
$this
->checkCode =
$this
->getCheckCode();
}
public
function
__toString(){
$string
= implode('',
$this
->getCheckCode());
$_SESSION
[
"code"
]=
$string
;
$this
->getImage();
return
'';
}
protected
function
getCheckCode(){
$string
=
array
();
switch
(
$this
->codeType){
case
1:
$string
=
array_rand
(range(0,9),
$this
->codeNum);
break
;
case
2:
$string
=
array_rand
(
array_flip
(range('A', 'Z')),
$this
->codeNum);
break
;
case
3:
for
(
$i
=0;
$icodeNum
);
$i
++){
$start
= mt_rand(0,
$this
->strNum);
$string
[
$i
]= self::msubstr(
$this
->codeStr,
$start
);
}
break
;
case
4:
for
(
$i
=0;
$icodeNum
);
$i
++){
$rand
=mt_rand(0,2);
switch
(
$rand
){
case
0:
$ascii
= mt_rand(48,57);
$string
[
$i
] = sprintf('%c',
$ascii
);
break
;