Use PHP to implement the password protection card function & lt; package, download, and run directly & gt

Source: Internet
Author: User
Tags password protection
PHP implements the password protection card function to implement code, which can be directly run after being downloaded ~! If you do not need a database or other data, you can download and decompress the data and put it in the environment to see the effect:

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 {
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 generation
Copy 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 Verification
Copy 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 network manager

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.