<?php //將驗證碼保存到session里,供全局使用 session_start(); $nums = ""; for($i=0;$i<4;$i++){ //產生隨機數并轉換成十六進制 $nums.=dechex(mt_rand(0,15)); } //將驗證碼寫入session $_SESSION['co " /> 日韩电影免费观看高清完整版,西西裸体人体做爰大胆久久久,亚洲一区网址

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

一個簡單的PHP驗證碼實現代碼

實現代碼:

<?php
 //將驗證碼保存到session里,供全局使用
 session_start();
 $nums = "";
 for($i=0;$i<4;$i++){
  //產生隨機數并轉換成十六進制
  $nums.=dechex(mt_rand(0,15));
 }
 //將驗證碼寫入session
 $_SESSION['code']=$nums;

 //設置驗證碼長和寬
 $_width = 60;
 $_height = 20;
 //創建一張圖片
 $_img = imagecreatetruecolor($_width,$_height);
 //創建一個白色
 $_white = imagecolorallocate($_img,220,250,250);
 //填充背景
 imagefill($_img,0,0,$_white);

 //隨機畫6條線條
 for($i=0;$i<6;$i++){
  $_rnd_color = imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  imageline($_img,mt_rand(0,$_width),mt_rand(0,$_width),mt_rand(0,$_width),mt_rand(0,$_width),$_rnd_color);
 }

 //隨機畫出雪花
 for($i=0;$i<60;$i++){
  imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),"*",imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
 }

 //輸出驗證碼
 for($i=0;$i<strlen($_SESSION['code']);$i++){
  imagestring($_img,mt_rand(6,10),$i*$_width/4+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));
 }

 //輸出和銷毀
 header("Content-Type:image/png");
 imagepng($_img);
 imagedestroy($_img);
?>

php技術一個簡單的PHP驗證碼實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 竹山县| 大丰市| 秦皇岛市| 卫辉市| 临洮县| 玉门市| 银川市| 柳州市| 临沂市| 宕昌县| 探索| 凤凰县| 页游| 吉林省| 浪卡子县| 乌审旗| 巴彦县| 塔河县| 刚察县| 乌拉特中旗| 达日县| 双柏县| 广汉市| 泸溪县| 枣强县| 昌江| 靖远县| 青海省| 舒城县| 昔阳县| 云阳县| 同德县| 平安县| 德安县| 孝昌县| 贵州省| 湘潭市| 桐梓县| 宣威市| 聂拉木县| 葵青区|