:
Security Card warehouse receiving
Copy codeThe Code is as follows: $ this-> load-> model ('admin/m_mibao ');
$ Data = array ();
// Generate random abscissa
$ Rand_str = $ this-> _ rand_str (10 );
$ Arr = array ();
For ($ k = 0; $ k <strlen ($ rand_str); $ k ++)
{
For ($ I = 1; $ I <9; $ I ++)
{
$ Rand = $ this-> _ rand_num (3 );
// Containers assigned to all codes
$ Arr [$ rand_str {$ k}. $ I] = $ rand;
}
}
$ Data ['code'] = serialize ($ arr); // import the information to the database after serialization.
$ Data ['letter'] = $ rand_str;
// Avoid repeated serial numbers
While (TRUE)
{
$ Data ['Card _ num'] = $ this-> _ rand_num (20 );
// Judge whether the serial number already exists
If ($ this-> m_mibao-> has_card_num ($ data ['Card _ num']) = 0)
{
Break;
}
}
$ Data ['add _ time'] = time;
$ Data ['user _ id'] = $ uid;
Echo $ this-> mibao-> insert ($ data );
Security Card Image GenerationCopy codeThe Code is as follows: // calculates coordinates.
Public function show ($ user_id)
{
$ This-> load-> model ('admin/m_mibao ');
$ Info = $ this-> m_mibao-> get_by_uid ($ user_id );
If (emptyempty ($ info ))
{
$ This-> msg ('the user does not have a security card! ', 'Admin-Index ');
}
$ Codes = unserialize ($ info ['code']);
// Initial image Value
$ Bit = 3; // Number of BCC cards
$ Height = 332; // Image height
$ Width = 626; // Image width
$ Im = imagecreatetruecolor ($ width, $ height );
$ Linecolor = imagecolorallocate ($ im, 229,229,229 );
$ Fontcolor = imagecolorallocate ($ im, 0, 0, 0 );
$ Top_rectangle_color = imagecolorallocate ($ im, 241,254,237 );
$ Top_letter_color = imagecolorallocate ($ im, 54,126, 76 );
$ Left_rectangle_color = imagecolorallocate ($ im, 243,247,255 );
$ Left_num_color = imagecolorallocate ($ im, 192 );
$ Logo_str_color = imagecolorallocate ($ im, 0, 0 );
Imagefill ($ im, 255,255,255, imagecolorallocate ($ im,); // specifies the background color of the image.
$ Font = './public/baomi/fonts/simsun. ttc'; // font
$ Font_en = './public/baomi/fonts/La. ttf'; // english font
$ Font2 = './public/baomi/fonts/simhei. ttf'; // The simhei above the security card
$ Dst = imagecreatefromjpeg ("./public/baomi/120.jpg ");
Imagecopymerge ($ im, $ dst, 100, 15 );
Imageline ($ im, 10, 72, $ width-10, 72, $ linecolor );
$ Ltext = "electronic security card ";
If (! Imagettftext ($ im, 10, 0, 47, $ logo_str_color, $ font2, $ ltext )){
Exit ('error ');
}
// Write the card number
$ B = '000000'. $ info ['Card _ num'];
For ($ I = 0; $ I <7; $ I ++ ){
$ P. = substr ($ B, 3 * $ I, 4 ).'';
}
$ X = 40; $ y = 95; // location of the serial number
Imagettftext ($ im, 10, 0, $ x, $ y, $ color, $ font, 'serial number ');
Imagettftext ($ im, 11,0, $ x + 50, $ y, $ color, $ font_en, $ p );
// Color box
Imagefilledrectangle ($ im, 10,106, $ width-10, 128, $ top_rectangle_color );
Imagefilledrectangle ($ im, 10,129, 65, $ height-10, $ left_rectangle_color );
// Write the upper lines of English letters and vertical bars
For ($ I = 1; $ I <= 10; $ I ++ ){
$ X = $ I * 55 + 35; $ y = 123; $ float_size = 11; // letter Location Parameter
Imagettftext ($ im, $ float_size, 0, $ x, $ y, $ top_letter_color, $ font_en, $ info ['Letter '] {$ I-1 }); // write the top row of English letters
}
For ($ I = 0; $ I <= 9; $ I ++ ){
$ Linex = $ I * 55 + 65; $ liney = 105; $ liney2 = $ height-10; // the parameter of the vertical line.
Imageline ($ im, $ linex, $ liney, $ linex, $ liney2, $ linecolor); // draw a vertical line
}
// Write a vertical number and fill in matrix data to draw a line
For ($ j = 0; $ j <8; $ j ++ ){
$ Jj = $ j + 1;
$ X = 35; $ y = ($ jj * 24) + 123; // left-side numeric and horizontal line parameters
Imagettftext ($ im, $ float_size, 0, $ x, $ y, $ left_num_color, $ font_en, $ jj); // write the number to the Left row
For ($ I = 1; $ I <= 10; $ I ++ ){
$ Float_size2 = 11; $ x = $ I * 55 + 27; $ sy = $ y; // fill in the matrix Data Location Parameter
$ S = $ info ['Letter '] {$ I-1 };
$ S. = $ j + 1;
Imagettftext ($ im, $ float_size2, 0, $ x, $ sy, $ fontcolor, $ font_en, $ codes [$ s]); // write matrix data
}
}
For ($ j = 0; $ j <10; $ j ++ ){
$ Line_x = 10; $ line_x2 = $ width-10; $ y = $ j * 24 + 105; // The y coordinate data of the X axis is the same as that of the X axis.
Imageline ($ im, $ line_x, $ y, $ line_x2, $ y, $ linecolor); // draw the line
}
// Outer frame edge
Imageline ($ im, 10, 10, $ width-10, 10, $ linecolor); // horizontal line
// Imageline ($ im, 10, $ height-10, $ width-10, $ height-10, $ linecolor );
Imageline ($ im, 10, 10, 10, $ height-10, $ linecolor); // vertical line
Imageline ($ im, $ width-10, 10, $ width-10, $ height-10, $ linecolor );
// Generate an image
Ob_clean ();
Header ("Content-type: image/jpeg ");
Imagejpeg ($ im, null, 100 );
Imagedestroy ($ im );
}
Security card verificationCopy codeThe Code is as follows: public function test1 ($ uid)
{
$ This-> load-> model ('admin/m_users ');
$ User = $ this-> m_users-> sel ($ uid );
// Submit post for verification
If ($ this-> is_post ())
{
$ Codes = $ this-> m_mibao-> get_codes_by_uid ($ uid );
$ Codes = unserialize ($ codes );
$ Is_true = true;
Foreach ($ _ SESSION ['mibao'] ['keys '] as $ key)
{
If ($ codes [$ key]! = $ _ POST ['values'] [$ key])
{
$ Is_true = false;
}
}
If ($ is_true)
{
Die ('true ');
}
Else
{
Die ('error ');
}
}
Else
{
// Rendering View
$ Info = $ this-> m_mibao-> get_by_uid ($ uid );
$ Data = array ();
$ Data ['keys '] = $ this-> m_mibao-> get_rand_keys ($ info ['Letter']);
$ _ SESSION ['mibao'] ['keys '] = $ data ['keys'];
$ Data ['uid'] = $ uid;
$ This-> load-> view ('test1', $ data );
}
Package and download the script