PHP (20140513)

Source: Internet
Author: User

PHP code to verify the CAPTCHA:

A four-digit verification code is randomly generated using random numbers.

1<?PHP2 3 Session_Start();4 $arr=Array(5' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' X ',6' Y ', ' z ', ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '7 );8 $rand= "";9  for($i= 1;$i<=4;$i++){Ten     $rand.=$arr[Rand(0,Count($arr)-1)]; One } A $_session[' check_pic '] =$rand; - //Create a picture - $im= Imagecreatetruecolor (100,30); the //Generate color , when the first call to generate a color method, is to generate a background color - $BG= Imagecolorallocate ($im, 0,0,0); - //The second call to this method is the ability to generate the text above the picture or the color of other styles - $te= Imagecolorallocate ($im, 255,255,255); +  - //create text on top of a picture +Imagestring ($im,Rand(1,5),Rand(3,70),Rand(3,15),$rand,$te); A //to take PHP as a picture output, you must give the file a header declaration at  - Ob_clean(); - Header("Content-type:image/jpeg"); - //Final image Generation -Imagejpeg ($im); -  in?>

Code to verify that the captcha is correct:

1 <HTML>2 <Head>3     <Metahttp-equiv= "Content-type" 4 5 content= "Text/html;charset=utf-8"/>6 </Head>7 <Body>8 9 <?PHPTen  One session_start (); A if (isset ($_post[' check ')) { - if ($_post[' check '] = = $_session[' Check_pic ']) { - echo "Verification success"; the }else{ - echo "Verification failed"; -     } - } + ?> -  + <formAction= "check2.php"Method= "POST"> A     <inputtype= "text"name= "Check"/> at     <imgsrc= "check1.php"alt=""onclick= "refreshimg ()"  -  - ID= "Chk"style= "Cursor:pointer"/> -     <BR/> -  -     <inputtype= "Submit"value= "Submit"/> in </form> - <Script> to functionrefreshimg () { + //avoid the same page that the browser thinks you have been accessing, so use random numbers to pass a -  the value to make it think that the access is a different page *     varRand=Math.Round (Math.random ()*10000); $     varchk=document.getElementById ("chk");Panax Notoginseng chk.src= "check1.php?num="+Rand; - } the </Script>

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.