Using PHP to implement the secret card function code < package download Run >_php tutorial directly

Source: Internet
Author: User
:

Security card Storage
Copy CodeThe code is as follows:
$this->load->model (' Admin/m_mibao ');
$data = Array ();
Generate Random Horizontal axis
$rand _str = $this->_rand_str (10);
$arr = Array ();
for ($k =0; $k {
for ($i = 1; $i < 9; $i + +)
{
$rand = $this->_rand_num (3);
Assign to all code containers
$arr [$rand _str{$k}. $i] = $rand;
}
}
$data [' code '] = serialize ($arr); Put information into storage after serialization
$data [' letter '] = $rand _str;
Avoid repeating serial numbers
while (TRUE)
{
$data [' card_num '] = $this->_rand_num (20);
Determine if the serial number is duplicated
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);

Secret card image generation
Copy CodeThe code is as follows:
That's the 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 has no secret insurance card! ', ' admin-index ');
}
$codes = Unserialize ($info [' Code ']);
Image Initial value
$bit = 3; Number of security card bits
$height = 332; Picture height
$width = 626; Picture 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, 4,68,192);
$logo _str_color = imagecolorallocate ($im, 0,0,0);
Imagefill ($im, 0,0,imagecolorallocate ($im, 255,255,255)); Picture background color
$font = './PUBLIC/BAOMI/FONTS/SIMSUN.TTC '; Font
$font _en = './public/baomi/fonts/consola. TTF '; English fonts
$font 2 = './public/baomi/fonts/simhei.ttf '; Black body above the secret card
$DST = Imagecreatefromjpeg ("./public/baomi/120.jpg");
Imagecopymerge ($im, $DST, 120,15,0,0,193,55,100);
Imageline ($im, 10,72, $width -10,72, $linecolor);
$ltext = "Electronic Security card";
if (!imagettftext ($im, 10,0,340,47, $logo _str_color, $font 2, $ltext)) {
Exit (' Error ');
}
Write card number
$b = ' 1000 '. $info [' Card_num '];
for ($i =0; $i <7; $i + +) {
$p. = substr ($b, $i, 4). ' ';
}
$x = 40; $y = 95; Serial number Location
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 top English letters and vertical lines
for ($i =1; $i <=10; $i + +) {
$x = $i *55+35; $y = 123; $float _size = 11; Letter Position Parameters
Imagettftext ($im, $float _size,0, $x, $y, $top _letter_color, $font _en, $info [' Letter ']{$i-1}]//write the top English letters
}
for ($i =0; $i <=9; $i + +) {
$linex = $i *55+65; $liney = 105; $liney 2 = $height-10; Vertical bar Position Parameters
Imageline ($im, $linex, $liney, $linex, $liney 2, $linecolor);//Enter Vertical line
}
Write vertical numbers and fill in the Matrix data dash
for ($j =0; $j <8; $j + +) {
$JJ = $j +1;
$x = 35; $y = ($jj *24) +123; Left row numbers and horizontal line position parameters
Imagettftext ($im, $float _size, 0, $x, $y, $left _num_color, $font _en, $JJ);//write left row number
for ($i =1; $i <=10; $i + +) {
$float _size2=11; $x = $i *55+27; $sy = $y; Fill in the matrix data position parameters
$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; Horizontal line position parameter y coordinate data ibid.
Imageline ($im, $line _x, $y, $line _x2, $y, $linecolor);//dash into the horizontal line
}
Outer border Edge
Imageline ($im, 10,10, $width -10,10, $linecolor);//Horizontal line
Imageline ($im, ten, $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);
Create a picture
Ob_clean ();
Header ("Content-type:image/jpeg");
Imagejpeg ($im, null,100);
Imagedestroy ($im);
}

Verification of the secret insurance card
Copy CodeThe code is as follows:
Public function test1 ($UID)
{
$this->load->model (' admin/m_users ');
$user = $this->m_users->sel ($uid);
Post submitted 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 (' correct ');
}
Else
{
Die (' Error ');
}
}
Else
{
Render 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);
}

Script Home Package Download

http://www.bkjia.com/PHPjc/324365.html www.bkjia.com true http://www.bkjia.com/PHPjc/324365.html techarticle : Secret card storage copy code code is as follows: $this-load-model (' Admin/m_mibao '); $data = Array ();//Generate random horizontal axis $rand _str = $this-_rand_str (ten); $arr = Array (); Fo ...

  • Related Article

    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.