TAILIEUCHUNG - Pro PHP Security phần 6

chắc chắn, mặc dù có những lúc, như PHP, bạn không tâm chấp nhận số là chuỗi. Trong trường hợp này, việc kiểm tra tốt nhất cho stringness có thể được kiểm tra để xem đó có sản phẩm nào () là FALSE. Hoặc, nếu bạn đếm một chuỗi rỗng như là một chuỗi, kiểm tra sau đây sẽ bao gồm tất cả các căn cứ: | CHAPTER 11 VALIDATING USER INPUT 237 sure although there are times when like PHP you don t mind accepting numbers as strings. In this case the best check for stringness may be checking to see that empty is FALSE. Or if you count an empty string as a string the following test will cover all the bases if isset value value NULL value is a possibly empty string according to PHP We will discuss empty and NULL values at greater length later in this chapter. String length is often very important more so than type. We will discuss length in detail later as well. Numbers If you are expecting a number like a year then receiving a nonnumeric response ought to raise red flags for you. Although it is true that PHP treats all form entries by default as string types its automatic type casting permits you to determine whether that string that the user entered is capable of being interpreted as numeric as it would have to be to be usable to your script . To do this you might use the is_int function or is_integer or is_long its aliases something like this year _POST year if is_int year exit year is an invalid value for year Note that the error message here does not provide guidance to an attacker about exactly what has gone wrong with the attempt. To provide such guidance would simply make things easier for the next attempt. We discuss providing error messages at length later in this chapter. PHP is such a rich and flexible language that there is at least one other way to carry out the same check by using the gettype function if gettype year integer exit year is an invalid value for year There are also at least three ways to cast the year variable to an integer. One way is to use the intval function like this year intval _POST year A second way to accomplish the same thing is to specifically cast the variable to an integer like this year int _POST year Both of these ways will generate an integer value of 0 if provided with an alphabetic string as input so they should not be used .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.