PHP authentication code implementation & lt ;? Phpinclude '../lib/function. php'; if (! Isset ($ _ SESSION )){??? Session_start ();??? Header ('cache-control: private ');} $ widt PHP authentication code implementation
Include '../lib/function. php ';
If (! Isset ($ _ SESSION )){
??? Session_start ();
??? Header ('cache-control: private ');
}
$ Width = 65;
$ Height = 20;
$ Image = imagecreate ($ width, $ height );
$ Bg_color = imagecolorallocate ($ image, 0x33, 0x66, 0xFF );
Imagefilledrectangle ($ image, 0, 0, $ width, $ height, $ bg_color );
$ Text = random_text (5 );
$ Font = 5;
$ X = imagesx ($ image)/2-strlen ($ text) * imagefontwidth ($ font)/2;
$ Y = imagesy ($ image)/2-imagefontheight ($ font)/2;
$ Fg_color = imagecolorallocate ($ image, 0xFF, 0xFF, 0xFF );
Imagestring ($ image, $ font, $ x, $ y, $ text, $ fg_color );
$ _ SESSION ['captcha '] = $ text;
Header ('content-type: image/png ');
Imagepng ($ image );
Imagedestroy ($ image );
?>
?
Function random_text ($ count, $ rm_similar = false)
{
??? $ Chars = array_flip (array_merge (range (0, 9), range ('A', 'z ')));
??? If ($ rm_similar ){
??????? Unset ($ chars [0], $ chars [1], $ chars [2], $ chars [5], $ chars [8], $ chars ['B'], $ chars ['I'],
??????????? $ Chars ['O'], $ chars ['Q'], $ chars ['s'], $ chars ['u'], $ chars ['V'], $ chars ['Z']);
??? }
??? For ($ I = 0, $ text = ''; $ I <$ count; $ I ++ ){
??????? $ Text. = array_rand ($ chars );
??? }
??? Return $ text;
}
?>