php编纂生成酷炫验证码
php编写生成酷炫验证码
<span style="color: #008080;"> 1</span> <span style="color: #000000;">php</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$im</span>=imagecreate(200,100<span style="color: #000000;">);//生成画布</span><span style="color: #008080;"> 3</span> imagecolorallocate(<span style="color: #800080;">$im</span>,0,0,0<span style="color: #000000;">);//背景色</span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$white</span>=imagecolorallocate(<span style="color: #800080;">$im</span>,<span style="color: #008080;">rand</span>(0,255),<span style="color: #008080;">rand</span>(0,255),<span style="color: #008080;">rand</span>(0,255<span style="color: #000000;">));//生成随机颜色</span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++<span style="color: #000000;">)</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">{</span><span style="color: #008080;"> 7</span> imageline(<span style="color: #800080;">$im</span>,<span style="color: #008080;">rand</span>(0,200),<span style="color: #008080;">rand</span>(0,100),<span style="color: #008080;">rand</span>(0,200),<span style="color: #008080;">rand</span>(0,100),<span style="color: #800080;">$white</span><span style="color: #000000;">);//生成干扰线条元素</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">}</span><span style="color: #008080;"> 9</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++<span style="color: #000000;">)</span><span style="color: #008080;">10</span> <span style="color: #000000;">{</span><span style="color: #008080;">11</span> imagesetpixel(<span style="color: #800080;">$im</span>,<span style="color: #008080;">rand</span>(0,200),<span style="color: #008080;">rand</span>(0,100),<span style="color: #800080;">$white</span><span style="color: #000000;">);//生成干扰点元素</span><span style="color: #008080;">12</span> <span style="color: #000000;">}</span><span style="color: #008080;">13</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0,<span style="color: #800080;">$str</span>='';<span style="color: #800080;">$i</span>$i++<span style="color: #000000;">)//通过循环获得四个字符</span><span style="color: #008080;">14</span> <span style="color: #000000;">{</span><span style="color: #008080;">15</span> <span style="color: #0000ff;">switch</span>(<span style="color: #008080;">rand</span>(1,3<span style="color: #000000;">))</span><span style="color: #008080;">16</span> <span style="color: #000000;"> {</span><span style="color: #008080;">17</span> <span style="color: #0000ff;">case</span>'1':<span style="color: #008080;">18</span> <span style="color: #800080;">$ch</span>=<span style="color: #008080;">rand</span>(0,9<span style="color: #000000;">);</span><span style="color: #008080;">19</span> <span style="color: #0000ff;">break</span><span style="color: #000000;">; </span><span style="color: #008080;">20</span> <span style="color: #0000ff;">case</span>'2':<span style="color: #008080;">21</span> <span style="color: #800080;">$ch</span>=<span style="color: #008080;">sprintf</span>('%c',<span style="color: #008080;">rand</span>(97,122<span style="color: #000000;">));</span><span style="color: #008080;">22</span> <span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #008080;">23</span> <span style="color: #0000ff;">case</span>'3':<span style="color: #008080;">24</span> <span style="color: #800080;">$ch</span>=<span style="color: #008080;">sprintf</span>('%c',<span style="color: #008080;">rand</span>(65,90<span style="color: #000000;">));</span><span style="color: #008080;">25</span> <span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #008080;">26</span> <span style="color: #000000;"> }</span><span style="color: #008080;">27</span> <span style="color: #800080;">$str</span>.=<span style="color: #800080;">$ch</span><span style="color: #000000;">;</span><span style="color: #008080;">28</span> <span style="color: #008080;">29</span> <span style="color: #000000;">}</span><span style="color: #008080;">30</span> imagettftext(<span style="color: #800080;">$im</span>,32,<span style="color: #008080;">rand</span>(0,15),55,70,<span style="color: #800080;">$white</span>,'c.ttc',<span style="color: #800080;">$str</span><span style="color: #000000;">);//在画布上输出字符串</span><span style="color: #008080;">31</span> <span style="color: #008080;">header</span>("Content-type:image/jpeg"<span style="color: #000000;">);</span><span style="color: #008080;">32</span> imagejpeg(<span style="color: #800080;">$im</span><span style="color: #000000;">);</span><span style="color: #008080;">33</span> imagedestroy(<span style="color: #800080;">$im</span><span style="color: #000000;">);</span><span style="color: #008080;">34</span> ?>
- 1楼陶士涵
- 叼

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Pendant le processus de développement ou d'apprentissage de l'utilisation de Golang, nous pouvons rencontrer le message d'erreur undefined:rand.Seed. Cette erreur se produit généralement lorsque vous devez utiliser un générateur de nombres aléatoires, car dans Golang, vous devez définir une valeur de départ de nombres aléatoires avant de pouvoir utiliser la fonction du package rand. Cet article explique comment résoudre cette erreur. 1. Présentez le package math/rand. Tout d’abord, nous devons introduire le package math/rand dans le code. exister

Synchronisation de la génération de nombres aléatoires dans la programmation simultanée Go : utilisez un mutex (sync.Mutex) pour contrôler l'accès au générateur de nombres aléatoires rand.Rand. Chaque goroutine acquiert le verrou mutex avant de générer des nombres aléatoires et libère le verrou mutex après l'avoir généré. Cela garantit qu’un seul goroutine à la fois peut accéder au générateur de nombres aléatoires, éliminant ainsi les courses aux données.

La fonction rand() utilise les mêmes graines initiales à chaque appel. La graine initiale par défaut est obtenue à partir de l'heure du système d'exploitation, mais elle n'a qu'une précision de la microseconde. Autrement dit, dans un laps de temps très court, de nombreux appels de fonction rand() utiliseront la même graine initiale, ce qui entraînera la même génération de nombres aléatoires. Alors, comment résoudre ce problème ?

Dans le langage Go, l'instruction break stop est utilisée pour sortir de la boucle dans une instruction en boucle et commencer à exécuter l'instruction après la boucle. L'instruction break peut terminer les blocs de code de for, switch et select. De plus, l'instruction break peut également ajouter une étiquette après l'instruction pour indiquer la sortie du bloc de code correspondant à une certaine étiquette. bloc de code de for, switch et select.

En PHP, break est utilisé pour sortir de la structure syntaxique actuelle et exécuter l'instruction suivante ; il peut être utilisé dans des instructions telles que switch, for, while et do while. Il peut terminer le code du corps de la boucle et en sortir. de la boucle actuelle immédiatement et exécutez les instructions suivantes après le code de la boucle. L'instruction break peut prendre un paramètre n, indiquant le nombre de niveaux à sortir de la boucle. Si vous souhaitez sortir de plusieurs boucles, vous pouvez utiliser n pour indiquer le nombre de niveaux à quitter. paramètre, la valeur par défaut est de sortir de la boucle actuelle.

Il est très courant d'utiliser des instructions switch en PHP pour sélectionner plusieurs branches. Habituellement, une instruction break est utilisée pour quitter l'instruction switch après chaque branche. Cependant, il existe des situations dans lesquelles nous ne souhaitons pas utiliser l'instruction break. Cet article présentera la situation de non-utilisation de break dans l'instruction switch PHP.

Dans l'article précédent, nous vous avons amené à apprendre plusieurs structures de contrôle de boucle en JS (boucles while et do-while, boucles for). Parlons des instructions break et continue pour sortir de la boucle. tout le monde!

Recherche et analyse du caractère aléatoire de la fonction rand en PHP Les nombres aléatoires sont largement utilisés en programmation informatique, et la fonction rand en PHP est l'une des méthodes couramment utilisées pour générer des entiers aléatoires. Cet article explorera le caractère aléatoire de la fonction rand en PHP et analysera ses caractéristiques de génération de nombres aléatoires à travers des exemples de code spécifiques. 1. Introduction à la fonction rand en PHP En PHP, la fonction rand peut être utilisée pour générer des entiers aléatoires dans une plage spécifiée. Sa syntaxe de base est la suivante : inrand(int$min
