Pro PHP Security phần 8

Để tạo ra các thách thức, tất cả những gì bạn cần làm là đặt các hình ảnh xác thực ở dạng HTML, và cung cấp một hộp nhập văn bản cho userA € đáp ứng s, cùng với một số hướng dẫn cơ bản. Mã cho sản phẩm có thách thức sau, và có thể được tìm thấy cũng như TRaeTYR7 | CHAPTER 17 ALLOWING ONLY HUMAN USERS 343 Figure 17-6. The generated captcha 3. Place the Captcha Image in a Form To create the challenge all you need to do is place the captcha image in an HTML form and provide a text input box for the user s response along with some basic instructions. The code for offering the challenge follows and can be found also as in the Chapter 17 folder of the downloadable archive of code for Pro PHP Security at http . hl Please Login hl p To prevent abuse by automated attempts to login we are asking you to type the word you see displayed below. em It you cannot see this image please contact US tor assistance. em p torm action _SERVER SCRIPT_NAME method post img src alt Type in the letters you see here. br input type text name captcha size 22 xbr input type submit value Login torm This is a standard HTML form with PHP needed only to specify the form action. The source for the image is the preceding script that generates the captcha. 4. Check the User s Response When the user submits the form you compare his answer to _SESSION captcha_word and if it matches then you can be reasonably certain that he is a human. The code for retrieving the user s response and comparing it to the correct response follows and can be found also as in the Chapter 17 folder of the downloadable archive of code for Pro PHP Security at http . com. php session_start it empty _POST captcha it isset _SESSION target print hl Sorry there was an error in logging in. Please contact US tor assistance. hl 344 CHAPTER 17 ALLOWING ONLY HUMAN USERS elseif _SESSION target _POST captcha print hl You have successfully logged in hl unset _SESSION target else print hl Incorrect You are not logged in. hl Checking the user s response is extremely simple. After creating a session so that the stored correct answer is available to this script you compare that to the user s response contained in the _POST .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
357    2    1    22-05-2024
129    493    2    22-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.