1. [代码]制作随机字符串
<?php print_r(join("",array_merge(range("a","z"),range("A","Z")))); echo '<br />'; $chars = join("",array_merge(range("a","z"),range("A","Z"),range("0","9"))); $chars = str_shuffle($chars); echo $chars; foreach (range(0, 12) as $number) { echo $number,'<br />'; } ?>
2. [代码]利用GD库制作验证码
<?php require_once("string_func.php"); //通过GD库做验证码 //创建画布 /* * @param $sess_name SESSION名称 * @param $type 验证码样式. 1:纯数字验证码; 2:纯字母验证码; 3:数字和字母混合验证码; * @param $length 验证码字符数量。 * @param $pixel 干扰点数量 * @param $line 干扰线数量 * */ function image_func($sess_name = "verify",$type = 1,$length = 4,$pixel = 50,$line=3) { session_start(); $width = 80; $height = 30; $image = imagecreatetruecolor($width, $height); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); //填充画布 imagefilledrectangle($image, 1, 1, $width - 2, $height - 2, $white); $chars = buildRandomString($type, $length); $_SESSION[$sess_name] = $chars; $fontfiles = array("msyh.ttc", "msyhbd.ttc", "simhei.ttf", "simsun.ttc", "Deng.ttf", "Dengb.ttf", "Dengl.ttf"); for ($i = 0; $i < $length; $i++) { $size = mt_rand(14, 18); $angle = mt_rand(-15, 15); $x = 5 + $i * $size; $y = mt_rand(20, 26); $fontfile = "fonts/" . $fontfiles[mt_rand(0, count($fontfiles) - 1)]; $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 120), mt_rand(90, 180)); $text = substr($chars, $i, 1); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text); } if ($pixel) { for ($i = 0; $i < $pixel; $i++) { $pointer_color = imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 200), mt_rand(50, 200)); imagesetpixel($image, mt_rand(0, 80), mt_rand(0, 30), $pointer_color); } } if ($line) { for ($i = 0; $i < $line; $i++) { $line_color = imagecolorallocate($image, mt_rand(100, 220), mt_rand(100, 220), mt_rand(100, 220)); imageline($image, mt_rand(0, 80), mt_rand(0, 30), mt_rand(0, 80), mt_rand(0, 30), $line_color); } } header("content-type:image/gif"); imagegif($image); imagedestroy($image); } return image_func('a',1,4,100,3); ?>
3. [代码]效果测试
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <img src="image_func.php" alt=""> </body> </html>
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事
アサシンのクリードシャドウズ:シーシェルリドルソリューション
3週間前ByDDD
Atomfallのクレーンコントロールキーカードを見つける場所
3週間前ByDDD
R.E.P.O.で節約説明した(そしてファイルを保存)
1 か月前By尊渡假赌尊渡假赌尊渡假赌

ホットツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

Dreamweaver Mac版
ビジュアル Web 開発ツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません
