PHP mobile phone number generation Picture Instance Program _php Tutorial

Source: Internet
Author: User
Previously did a recruitment site so we need to let not collect our customer's mobile phone number and email address, so we will use PHP to realize from the database read the mobile phone number and email address directly generated a picture, so that the past can only be a picture and can not be recognized, below I would like to introduce you to two examples.


PHP string processing-Mobile phone number to live picture

The code is as follows Copy Code

The phone number turns into a picture
$str the string to display, $rand whether to enable the scrambling code
function Str_to_image ($str, $w =130, $h =25, $rand =true)
{
Generate a 11-bit digital picture
Header ("Content-type:image/png"); Tell the browser that the following data is a picture, not a text display
Define Picture Width height
$nwidth = $w;
$nheight = $h;
Srand (Double) microtime () *1000000); Gets the current time of one out of 10,000 seconds value to execute when the random number of one out of 10,000 seconds seeds
$randval = $str; 11-digit Number
$im = @imagecreate ($nwidth, $nheight) or Die ("Can ' t initialize new GD image stream"); Creating images
Picture color settings
$background _color=imagecolorallocate ($im, 255,255,255); Match color
$text _color=imagecolorallocate ($im, 23,14,91);
Draw a picture border
Imagefilledrectangle ($im, 0,0, $nwidth-1, $nheight-1, $background); Rectangle Area Coloring
Imagerectangle ($im, 0,0, $nwidth-1, $nheight-1, $background _color); Draw a rectangle
Imagestring ($im, 8,10,4, $randval, $text _color); Draw a cross-string
if ($rand) {
Adding interference factors
for ($i =0; $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); Creating PNG patterns
Imagedestroy ($im); End chart Type
}

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

Example 2

The code is as follows Copy Code


$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-bit digital picture
Header ("Content-type:image/png"); Tell the browser that the following data is a picture, not a text display

Define Picture Width height
$nwidth = 120;
$nheight = 25;
$im = @imagecreate ($nwidth, $nheight) or Die ("Can ' t initialize new GD image stream"); Creating images

Picture color settings
$background _color=imagecolorallocate ($im, 255,255,255); Match color
$text _color=imagecolorallocate ($im, 23,14,91);

Draw a picture border
Imagefilledrectangle ($im, 0,0, $nwidth-1, $nheight-1, $background); Rectangle Area Coloring
Imagerectangle ($im, 0,0, $nwidth-1, $nheight-1, $background _color); Draw a rectangle

Srand (Double) microtime () *1000000); Gets the current time of one out of 10,000 seconds value to execute when the random number of one out of 10,000 seconds seeds
$randval =rand ();
$randval = $p; 5-digit number
Imagestring ($im, 8,10,2, $randval, $text _color); Draw a cross-string


Adding 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); Creating PNG patterns
Imagedestroy ($im); End chart Type

}else{
echo "The merchant did not enter a phone number";
}

?>

http://www.bkjia.com/PHPjc/632785.html www.bkjia.com true http://www.bkjia.com/PHPjc/632785.html techarticle once done a recruitment site so we need to let not collect our customers mobile phone number and e-mail address, so we will use PHP to achieve from the database read the mobile phone number ...

  • 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.