PHP Mobile Phone Number Generation Image instance Program

Source: Internet
Author: User

We have worked on a recruitment website before, so we need to make sure that we cannot collect the mobile phone numbers and email addresses of our customers, therefore, we will use php to generate an image directly from the mobile phone number and email address read from the database. In this way, we can only collect pictures and cannot recognize them, next I will introduce two instances.


PHP string processing-survival pictures of mobile phone numbers

 

The Code is as follows: Copy code

<? Php
/// Convert the phone number into an image
// $ Str indicates the string to be displayed. $ rand indicates whether to enable the scrambling code.
Function str_to_image ($ str, $ w = 130, $ h = 25, $ rand = true)
{
// Generate an 11-digit Digital Image
Header ("Content-type: image/png"); // tell the browser that the following data is an image instead of Text
// Define the image width and height
$ Nwidth = $ w;
$ Nheight = $ h;
// Srand (double) microtime () * 1000000); // obtain the value of one second in the current time to one second in the execution time.
$ Randval = $ str; // 11 digits
$ Im = @ imagecreate ($ nwidth, $ nheight) or die ("Can't initialize new GD image stream"); // create an image
// Set the image color
$ Background_color = imagecolorallocate ($ im, 255,255,255); // match the color
$ Text_color = imagecolorallocate ($ im, 23, 14, 91 );
// Draw the image border
Imagefilledrectangle ($ im, $ nwidth-1, $ nheight-1, $ background); // rectangular area coloring
Imagerectangle ($ im, $ nwidth-1, $ nheight-1, $ background_color); // draw a rectangle
Imagestring ($ im, 8, 10, 4, $ randval, $ text_color); // draw a horizontal string
If ($ rand ){
// Add Interference Factors
For ($ I = 0; I I <260; $ I ++)
{
$ Randcolor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () % ($ nwidth-5), rand () % ($ nheight + 5), $ randcolor); // point
}
}
// Imagestring ($ im, 3,5, 5, "A Simple Text String", $ text_color );
// Imageinterlace ($ im, 1 );
Imagepng ($ im); // create a png Image
Imagedestroy ($ im); // end chart type
}

$ Str = '000000 ';
Echo str_to_image ($ str, $ w = 130, $ h = 25, $ rand = true)

Example 2

The Code is as follows: Copy code


<? Php // do not leave blank lines
$ Id = $ _ GET [id];
Include ("admin/config. php ");
$ SQL = "select * from user where id = $ id ";
$ Data = mysql_fetch_array (mysql_query ($ SQL ));
$ P = SBC_DBC ($ data [Phone], 1 );
Function get_str ($ str, $ strlen = 16 ){
$ Str = stripslashes ($ str );
For ($ I = 0; $ I <$ strlen; $ I ++)
If (ord (substr ($ str, $ I, 1)> 0xa0) $ j ++;
If ($ j % 2! = 0) $ strlen ++;
$ Tmp_str = substr ($ str, 0, $ strlen );
Return $ tmp_str;
}
If ($ p <> ''){
// Generate a 5-digit Digital Image
Header ("Content-type: image/png"); // tell the browser that the following data is an image instead of Text

// Define the image width and height
$ Nwidth = 120;
$ Nheight = 25;
$ Im = @ imagecreate ($ nwidth, $ nheight) or die ("Can't initialize new GD image stream"); // create an image

// Set the image color
$ Background_color = imagecolorallocate ($ im, 255,255,255); // match the color
$ Text_color = imagecolorallocate ($ im, 23, 14, 91 );

// Draw the image border
Imagefilledrectangle ($ im, $ nwidth-1, $ nheight-1, $ background); // rectangular area coloring
Imagerectangle ($ im, $ nwidth-1, $ nheight-1, $ background_color); // draw a rectangle

// Srand (double) microtime () * 1000000); // obtain the value of one second in the current time to one second in the execution time.
// $ Randval = rand ();
$ Randval = $ p; // 5-digit
Imagestring ($ im, 8, 10, 2, $ randval, $ text_color); // draw a horizontal string


// Add Interference Factors
// For ($ I = 0; $ I <478; $ I ++)
//{
// $ Randcolor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
// Imagesetpixel ($ im, rand () % 100, rand () % 30, $ randcolor); // point
//}
// Imagestring ($ im, 3,5, 5, "A Simple Text String", $ text_color );
// Imageinterlace ($ im, 1 );
Imagepng ($ im); // create a png Image
Imagedestroy ($ im); // end chart type

} Else {
Echo "<font size = 2> the merchant did not enter the phone number </font> ";
}

?>

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.