Use PHP to implement the secret card function to implement code < package download Direct run >_php tips

Source: Internet
Author: User
Tags rand
Effect Chart:

Secret Security card Storage
Copy Code code as follows:

$this->load->model (' Admin/m_mibao ');
$data = Array ();
Generating Random Horizontal
$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);
A container assigned to all code
$arr [$rand _str{$k}. $i] = $rand;
}
}
$data [' code '] = serialize ($arr); Storing information after serialization
$data [' letter '] = $rand _str;
Avoid duplicate serial numbers
while (TRUE)
{
$data [' card_num '] = $this->_rand_num (20);
Determine if serial numbers are repeated
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 picture Generation
Copy Code code as follows:

It'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 security card! ', ' admin-index ');
}
$codes = Unserialize ($info [' Code ']);
Picture Initial value
$bit = 3; Number of secret-keeping cards
$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 '; Top Black in 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 secret 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, 3* $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 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 top English letters
}
For ($i =0 $i <=9; $i + +) {
$linex = $i *55+65; $liney = 105; $liney 2 = $height-10; Vertical position parameter
Imageline ($im, $linex, $liney, $linex, $liney 2, $linecolor);//Vertical bar
}
Write vertical numbers and fill in matrix data dashes
For ($j =0 $j <8; $j + +) {
$JJ = $j +1;
$x = 35; $y = ($jj *24) +123; Left row digit and horizontal line position parameter
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 location 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 ditto
Imageline ($im, $line _x, $y, $line _x2, $y, $linecolor);/Dash line
}
Outer border
Imageline ($im, 10,10, $width -10,10, $linecolor);/Horizontal Line
Imageline ($im, $height -10, $width -10, $height -10, $linecolor);
Imageline ($im, 10,10,10, $height -10, $linecolor);//Vertical bar
Imageline ($im, $width -10,10, $width -10, $height -10, $linecolor);
Generate pictures
Ob_clean ();
Header ("Content-type:image/jpeg");
Imagejpeg ($im, null,100);
Imagedestroy ($im);
}

Secret Security card Verification
Copy Code code as follows:

Public function test1 ($UID)
{
$this->load->model (' admin/m_users ');
$user = $this->m_users->sel ($uid);
Post submit 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);
}

Cloud-dwelling Community package download

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.