Generate verification code a php code to generate the verification code and customize the session directory. This is not php. the default session file path in ini is saved, as shown in session_save_path below. You can redefine the directory.
Generate Verification Code
A php tutorial generates the verification code and defines the session directory. This is not the default session file storage path in php. ini, as shown below
Session_save_path, You can redefine the directory.
*/
$ Sesssavepath = dirname (_ file _). "/../data/sessions /";
If (is_writeable ($ sesssavepath) & is_readable ($ sesssavepath) {session_save_path ($ sesssavepath );}
Session_start ();
$ Vstr = '';
For ($ I = 0; $ I <4; $ I ++) $ vstr. = chr (mt_rand (65,90 ));
If (function_exists ("imagecreate ")){
$ Ntime = time ();
If (empty ($ _ session ['verifycode _ la']) | empty ($ _ session ['verifycode']) | ($ ntime-$ _ session ['verifycode _ la']> 5 )){
$ _ Session ['verifycode'] = strtolower ($ vstr );
$ _ Session ['verifycode _ la'] = $ ntime;
}
$ Vstr = $ _ session ['verifycode'];
$ Vstrlen = strlen ($ vstr );
$ Img = imagecreate (50, 20 );
Imagecolorallocate ($ img, 255,255,255 );
$ Line1 = imagecolorallocate ($ img, 240,220,180 );
$ Line2 = imagecolorallocate ($ img, 250,250,170 );
For ($ j = 3; $ j <= 16; $ j = $ j + 3 ){
Imageline ($ img, 2, $ j, 48, $ j, $ line1 );
}
For ($ j = 2; $ j <52; $ j = $ j + (mt_rand (3,6 ))){
Imageline ($ img, $ j, 2, $ j-6, 18, $ line2 );
}
$ Bordercolor = imagecolorallocate ($ img, 0x99,0x99,0x99 );
Imagerectangle ($ img, 0, 0, 49, 19, $ bordercolor );
$ Fontcolor = imagecolorallocate ($ img, 48, 61, 50 );
For ($ I = 0; $ I <$ vstrlen; $ I ++ ){
$ Bc = mt_rand (0, 1 );
$ Vstr [$ I] = strtoupper ($ vstr [$ I]);
Imagestring ($ img, 5, $ I * 10 + 6, mt_rand (2, 4), $ vstr [$ I], $ fontcolor );
}
Header ("pragma: no-cachern ");
Header ("cache-control: no-cachern ");
Header ("expires: 0rn ");
If (function_exists ("imagejpeg ")){
Header ("content-type: image/policrn ");
Imagejpeg ($ img );
} Else {
Header ("content-type: image/pngrn ");
Imagepng ($ img );
}
Imagedestroy ($ img );
Exit ();
}