<? Php $ Admin_pw = "admin"; // manage the 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"> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> log on </title> </Head> <Body> <Form action = "" method = "post"> Enter the password: <input type = "password" name = "password" style = "width: 100px;"/> <br/> Verification character: <input type = "text" style = "width: 40px;" name = "yz"/> <a href = "#" onclick = "document. tzm. src = '? Action = getcode'; "> </a> <br/> <input type =" submit "value =" Enter manage "/> </Form> </Body> </Html> <? Php } Else { ?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> File Upload </title> </Head> <Body> <? Php If ($ _ POST ['ac'] = "upload ") { $ Fileall = explode ('.', $ _ FILES ['file'] ['name']); $ Filetype = $ fileall [count ($ fileall)-1]; $ Filename = $ uploaddir. "/". $ _ FILES ['file'] ['name']. "_". rand (1,99999999999). ".". $ filetype; $ Fileexists = file_exists ($ filename ); While ($ fileexists = true) { $ Filename = $ uploaddir. "/". $ _ FILES ['file'] ['name']. "_". rand (1,99999999999). ".". $ 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. "uploaded successfully! <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 "/> <input type =" submit "value =" Upload "/> </Form> <P> <a href = "? Action = logout "> log out </a> </p> </Body> </Html> <? Php } Function setcode () { Header ("Content-type: image/gif "); $ Border = 0; // whether the border is required; 1: 0: not required $ How = 4; // number of digits of the Verification Code $ W = $ how * 15; // Image Width $ H = 20; // Image Height $ Fontsize = 5; // font size $ Alpha = "abcdefghijkmnopqrstuvwxyz"; // Verification Code content 1: letter $ Number = "0123456789"; // Verification Code content 2: number $ Randcode = ""; // verification code string Initialization Srand (double) microtime () * 1000000); // initialize the random number Seed $ Im = ImageCreate ($ w, $ h); // create a verification Image $ Bgcolor = ImageColorAllocate ($ im, 255,255,255); // you can specify the background color. ImageFill ($ im, 0, 0, $ bgcolor); // fill the background color If ($ border) { $ Black = ImageColorAllocate ($ im, 0, 0, 0); // you can specify the border color. ImageRectangle ($ im, 0, 0, $ W-1, $ h-1, $ black); // draw a border } For ($ I = 0; $ I <$ how; $ I ++) { $ Alpha_or_number = mt_rand (0, 1); // letters or numbers $ Str = $ alpha_or_number? $ Alpha: $ number; $ Which = mt_rand (0, strlen ($ str)-1); // specify the character $ Code = substr ($ str, $ which, 1); // obtain the character $ J =! $ I? 4: $ j + 15; // specifies the position of the painted character. $ Color3 = ImageColorAllocate ($ im, mt_rand (0,100), mt_rand (0,100), mt_rand (0,100); // Character Color ImageChar ($ im, $ fontsize, $ j, 3, $ code, $ color3); // draw characters $ Randcode. = $ code; // Add a verification code string to a bit by bit } $ _ SESSION ['yzcode'] = $ randcode; Imagegif ($ im ); ImageDestroy ($ im ); } ?>
|