首頁 > 後端開發 > php教程 > php编写生成酷炫验证码,php酷炫验证码_PHP教程

php编写生成酷炫验证码,php酷炫验证码_PHP教程

WBOY
發布: 2016-07-12 08:53:53
原創
782 人瀏覽過

php编写生成酷炫验证码,php酷炫验证码

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

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1122767.htmlTechArticlephp编写生成酷炫验证码,php酷炫验证码 1 ? php 2 $im =imagecreate(200,100 );//生成画布 3 imagecolorallocate( $im ,0,0,0 );//背景色 4 $white =imagecolorallocate(...
相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板