Php security card-PHP source code

Source: Internet
Author: User
Php Security Card

1. [image] 2.png


2. [code] warehouse receiving of the security card
$ This-> load-> model ('admin/m_mibao'); $ data = array (); // Generate random abscissa $ rand_str = $ this-> _ rand_str (10); $ arr = array (); for ($ k = 0; $ k
 < 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 into the database after serialization $ data ['letter '] = $ rand_str; // avoid repeated serial numbers while (TRUE) {$ data ['card _ num'] = $ this-> _ rand_num (20 ); // Determine 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 );
 
3. [code] BCC card image generation
// Calculate the coordinate public function show ($ user_id) {$ this-> load-> model ('admin/m_mibao '); $ info = $ this-> m_mibao-> get_by_uid ($ user_id); if (empty ($ 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 = imagec Olorallocate ($ im, 243,247,255); $ left_num_color = imagecolorallocate ($ im, 192,); $ logo_str_color = imagecolorallocate ($ im, 0); imagefill ($ im, 0, 0, imagecolorallocate ($ im, 255,255,255); // image background color $ font = '. /public/baomi/fonts/simsun. ttc '; // font $ font_en = '. /public/baomi/fonts/CONSOLA. ttf'; // English font $ font2 = '. /public/baomi/fonts/simhei. ttf'; // The black body $ dst = imagecreatefromjpeg (". /public/baomi/120.jpg"); im Agecopymerge ($ im, $ dst, 100, 15,); imageline ($ im, $ width-10, 72, $ linecolor ); $ ltext = "electronic security card"; if (! Imagettftext ($ im, 10, 0, 1000, 47, $ logo_str_color, $ font2, $ ltext) {exit ('error');} // write the card number $ B = '123 '. $ info ['card _ num']; for ($ I = 0; $ I <7; $ I ++) {$ p. = substr ($ B, 3 * $ I, 4 ). '';} $ x = 40; $ y = 95; // The position 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-right English letters and vertical bars for ($ I = 1; $ I <= 10; $ I ++) {$ x = $ I * 55 + 35; $ y = 123; $ float_size = 11; // The 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 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; // imagettftext ($ im, $ float_size, 0, $ x, $ y, $ left_num_color, $ font_en, $ jj ); // write the number in 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 imageline ($ im, $ line_x, $ y, $ line_x2, $ y, $ linecolor ); // draw a horizontal line} // The imageline ($ im, 10, 10, $ width-10, 10, $ linecolor) of the outer frame edge; // The 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 );}
4. [code] security card verification
Public function test1 ($ uid) {$ this-> load-> model ('admin/m_users'); $ user = $ this-> m_users-> sel ($ uid ); // post submitted to verify 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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.