<?php $admin _pw= "admin";//admin password $uploaddir = "upload";//Upload Directory Session_Start (); if ($_get[' action ']== "GetCode") { Setcode (); Exit (); } if ($_post[' password ']== $admin _pw && $_post[' yz ']==$_session[' Yzcode ']) { $_session[' logined ']= $admin _pw; } if ($_get[' action ']== "logout") { $_session[' logined ']= ' "; Header ("Location:". $_server[' php_self ')); Exit (); } if ($_session[' logined ']!= $admin _PW) { ?> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title> Please login </title> <body> <form action= "" method= "POST" > Enter Password: <input type= "password" name= "password" style= "width:100px;"/><br/> Authentication characters: <input type= "text" style = "width:40px" name= "YZ"/><a href= "#" onclick= "document.tzm.src=" Action=getcode ' ";" ></a><br/><input type= "Submit" Value= "Access Management"/> </form> </body> <?php } Else { ?> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title> File Upload </title> <body> <?php if ($_post[' ac ']== "upload") { $fileall =explode ('. ', $_files[' file '] [' name ']); $filetype = $fileall [Count ($fileall)-1]; $filename = $uploaddir. " /". $_files[' file ' [' Name ']." _ ". Rand (1,999999999).". $filetype; $fileexists =file_exists ($filename); while ($fileexists ==true) { $filename = $uploaddir. " /". $_files[' file ' [' Name ']." _ ". Rand (1,999999999).". $filetype; $fileexists =file_exists ($filename); } if (Move_uploaded_file ($_files["file"] ["Tmp_name"], $filename)) { $url = "http://". $_server[' server_name '].$_server[' Request_uri ']; echo "File:". $filename. "Upload success! <br> file Address: <input type=text style= ' width:350px ' value= '. DirName ($url). " /". $filename."/><a href= ". DirName ($url). /". $filename." target= "_blank" > Test </a> "; } Else { echo "File". $filename. " Upload failed! "; } } ?> <form action= "" method= "Post" enctype= "Multipart/form-data" > Select File: <input type= "file" name= "file" id= "file" width= "100px"/><input type= "hidden" name= "ac" value= "upload"/& Gt;<input type= "Submit" value= "Upload"/> </form> <p><a href= "? action=logout" > Exit login </a></p> </body> <?php } function Setcode () { Header ("Content-type:image/gif"); $border = 0; Do you want to have a border 1:0 don't $how = 4; Verify code digits $w = $how *15; Picture width $h = 20; Picture height $fontsize = 5; Font size $alpha = "ABCDEFGHIJKMNOPQRSTUVWXYZ"; CAPTCHA content 1: Letters $number = "0123456789"; Authenticode Content 2: Numbers $randcode = ""; Authentication Code String Initialization Srand (Double) microtime () *1000000); Initialize random number of seeds $im = Imagecreate ($w, $h); Create a validation picture $bgcolor = Imagecolorallocate ($im, 255, 255, 255); Set Background color Imagefill ($im, 0, 0, $bgcolor); Fill background color if ($border) { $black = imagecolorallocate ($im, 0, 0, 0); Set Border color Imagerectangle ($im, 0, 0, $w-1, $h-1, $black);//Draw Border } for ($i =0; $i < $how; $i + +) { $alpha _or_number = Mt_rand (0, 1); A letter or a number $str = $alpha _or_number? $alpha: $number; $which = Mt_rand (0, strlen ($str)-1); which character to take $code = substr ($str, $which, 1); Take characters $j = $i? 4: $j +15; Draw character position $color 3 = imagecolorallocate ($im, Mt_rand (0,100), Mt_rand (0,100), Mt_rand (0,100)); Character immediately color Imagechar ($im, $fontsize, $j, 3, $code, $color 3); Painting characters $randcode. = $code; Step by step to add a verification code string } $_session[' yzcode ' = $randcode; Imagegif ($im); Imagedestroy ($im); } ?> |