Làm cách nào để kiểm tra yêu cầu HTTP trong PHP?

là một thành phần đóng gói yêu cầu HTTP thực tế (thường được tạo bởi trình duyệt) và được gửi đến ứng dụng của chúng tôi. Đối tượng là một đối tượng giá trị đơn giản được truyền giữa các lớp điều phối và điều khiển, bao bọc môi trường yêu cầu HTTP. Nó cũng cung cấp quyền truy cập dễ dàng vào thông tin như dữ liệu tiêu đề, tệp, phương thức, biến, v.v.

isPost()) {
    // AJAX
    if (true === $request->isAjax()) {
        // ....
    }
}

Nhận giá trị

PHP tự động điền vào các mảng siêu toàn cầu $_GET, $_POST và $_REQUEST tùy thuộc vào loại yêu cầu. Các mảng này chứa các giá trị có trong các biểu mẫu được gửi hoặc các tham số được gửi qua URL. Các biến trong mảng không bao giờ được làm sạch và có thể chứa các ký tự không hợp lệ hoặc thậm chí là mã độc hại, điều này có thể dẫn đến các cuộc tấn công SQL injection hoặc Cross Site Scripting (XSS)

cho phép bạn truy cập các giá trị được lưu trữ trong các mảng $_GET, $_POST và $_REQUEST và khử trùng hoặc lọc chúng bằng dịch vụ bộ lọc

Có 5 phương pháp cho phép bạn truy xuất dữ liệu đã gửi từ một yêu cầu

Tất cả (ngoại trừ

get('userEmail', 'email', '[email protected]');
6) chấp nhận các thông số sau

  • get('userEmail', 'email', '[email protected]');
    
    8 tên của giá trị cần lấy
  • get('userEmail', 'email', '[email protected]');
    
    9 (mảng/chuỗi) chất khử trùng để áp dụng cho giá trị
  • get('userEmail', null, '[email protected]');
    
    0 được trả về nếu phần tử không được xác định (_______9_______1)
  • get('userEmail', null, '[email protected]');
    
    2 nếu được đặt (mặc định) và giá trị trống, thì
    get('userEmail', null, '[email protected]');
    
    0 sẽ được trả về;
  • get('userEmail', null, '[email protected]');
    
    5 áp dụng đệ quy các chất khử trùng trong giá trị (nếu giá trị là một mảng)

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed

get('userEmail', 'email', '[email protected]');
6 chỉ chấp nhận biến
get('userEmail', 'email', '[email protected]');
8 (chuỗi), đại diện cho tên của biến máy chủ mà bạn cần truy xuất

$_REQUEST

Siêu toàn cục $_REQUEST chứa một mảng kết hợp chứa nội dung của $_GET, $_POST và $_COOKIE. Bạn có thể lấy dữ liệu được lưu trữ trong mảng bằng cách gọi phương thức

get('userEmail', 'email', '[email protected]');
2 trong đối tượng như sau

Ví dụ Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail');
0

get('userEmail');

Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail');
0. Vệ sinh giá trị bằng chất khử trùng
getQuery('userEmail');
3

get('userEmail', 'email', '[email protected]');

Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail');
0. Đừng vệ sinh nó. Nếu tham số là null, trả về giá trị mặc định

get('userEmail', null, '[email protected]');

$_GET

$_GET superglobal chứa một mảng kết hợp chứa các biến được truyền tới tập lệnh hiện tại thông qua các tham số URL (còn được gọi là chuỗi truy vấn). Bạn có thể lấy dữ liệu được lưu trữ trong mảng bằng cách gọi phương thức

get('userEmail', 'email', '[email protected]');
3 như sau

Ví dụ Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail');
8

getQuery('userEmail');

Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail');
8. Vệ sinh giá trị bằng chất khử trùng
getQuery('userEmail');
3

getQuery('userEmail', 'email', '[email protected]');

Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail');
8. Đừng vệ sinh nó. Nếu tham số là null, trả về giá trị mặc định

getQuery('userEmail', null, '[email protected]');

$_POST

$_POST superglobal chứa một mảng kết hợp chứa các biến được chuyển đến tập lệnh hiện tại thông qua phương thức HTTP POST khi sử dụng

getQuery('userEmail', 'email', '[email protected]');
4 hoặc
getQuery('userEmail', 'email', '[email protected]');
5 làm HTTP
getQuery('userEmail', 'email', '[email protected]');
6 trong yêu cầu. Bạn có thể lấy dữ liệu được lưu trữ trong mảng bằng cách gọi phương thức
get('userEmail', 'email', '[email protected]');
4 như sau

Ví dụ Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail', 'email', '[email protected]');
9

getPost('userEmail');

Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail', 'email', '[email protected]');
9. Vệ sinh giá trị bằng chất khử trùng
getQuery('userEmail');
3

getPost('userEmail', 'email', '[email protected]');

Lấy trường

get('userEmail', null, '[email protected]');
9 từ siêu toàn cầu
getQuery('userEmail', 'email', '[email protected]');
9. Đừng vệ sinh nó. Nếu tham số là null, trả về giá trị mặc định

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
0

Đặt

Đối tượng yêu cầu phân tích luồng PUT đã được nhận nội bộ. Bạn có thể lấy dữ liệu được lưu trữ trong mảng bằng cách gọi phương thức

get('userEmail', 'email', '[email protected]');
5 như sau

Ví dụ Lấy trường

get('userEmail', null, '[email protected]');
9 từ luồng
getQuery('userEmail', null, '[email protected]');
7

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
1

Lấy trường

get('userEmail', null, '[email protected]');
9 từ luồng
getQuery('userEmail', null, '[email protected]');
7. Vệ sinh giá trị bằng chất khử trùng
getQuery('userEmail');
3

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
2

Lấy trường

get('userEmail', null, '[email protected]');
9 từ luồng
getQuery('userEmail', null, '[email protected]');
7. Đừng vệ sinh nó. Nếu tham số là null, trả về giá trị mặc định

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
3

$_SERVER

$_SERVER superglobal chứa một mảng chứa thông tin như tiêu đề, đường dẫn và vị trí tập lệnh. Bạn có thể lấy dữ liệu được lưu trong mảng bằng cách gọi phương thức

get('userEmail', 'email', '[email protected]');
6 như sau

Ví dụ Lấy giá trị

getPost('userEmail');
4 từ siêu toàn cầu
getPost('userEmail');
5

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
4

Chất khử trùng cài sẵn

Việc một số trường nhất định sử dụng cùng một tên trong ứng dụng của bạn là điều tương đối phổ biến. Một trường được đăng từ một biểu mẫu trong ứng dụng của bạn có thể có cùng tên và chức năng với một biểu mẫu khác ở một khu vực khác. Ví dụ về hành vi này có thể là các trường

getPost('userEmail');
6,
get('userEmail', 'email', '[email protected]');
8, v.v.

Để làm cho quá trình làm sạch dễ dàng hơn, khi truy xuất các trường như vậy, hãy cung cấp một phương pháp để xác định các bộ lọc làm sạch đó dựa trên các phương thức HTTP khi thiết lập đối tượng

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
5

Ở trên sẽ tự động làm sạch bất kỳ tham số nào được ĐĂNG từ một biểu mẫu có tên

getPost('userEmail');
6 hoặc
get('userEmail', 'email', '[email protected]');
8 với các bộ lọc tương ứng của chúng. Quá trình khử trùng diễn ra khi gọi các phương thức sau (một phương thức cho mỗi phương thức HTTP)

Các phương thức này chấp nhận các tham số giống như

get('userEmail', 'email', '[email protected]');
4,
get('userEmail', 'email', '[email protected]');
5 và
get('userEmail', 'email', '[email protected]');
3 nhưng không có tham số
getPost('userEmail', 'email', '[email protected]');
6

Bộ điều khiển

Nếu bạn sử dụng vùng chứa, vùng chứa đã được đăng ký cho bạn. Nơi phổ biến nhất để truy cập môi trường yêu cầu là trong hành động của bộ điều khiển. Để truy cập đối tượng từ bộ điều khiển, bạn sẽ cần sử dụng thuộc tính công khai

getPost('userEmail', 'email', '[email protected]');
7 của bộ điều khiển

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
6

Kiểm tra hoạt động

Thành phần chứa một số phương thức giúp bạn kiểm tra hoạt động hiện tại. Chẳng hạn, nếu bạn muốn kiểm tra xem một yêu cầu cụ thể có được thực hiện bằng AJAX hay không, bạn có thể làm như vậy bằng cách sử dụng phương thức

getPost('userEmail', 'email', '[email protected]');
8. Tất cả các phương thức đều có tiền tố là
getPost('userEmail', 'email', '[email protected]');
9

  • getPost('userEmail', 'email', '[email protected]');
    
    8. Kiểm tra xem yêu cầu đã được thực hiện bằng AJAX chưa
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    01. Kiểm tra xem phương thức HTTP có CONNECT hay không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    02. Kiểm tra xem phương thức HTTP có bị XÓA không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    03. Kiểm tra xem phương thức HTTP có phải là GET không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    04. Kiểm tra xem phương thức HTTP có phải là HEAD không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    05. Kiểm tra xem phương thức HTTP có khớp với bất kỳ phương thức nào đã thông qua không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    06. Kiểm tra xem phương thức HTTP có phải là TÙY CHỌN không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    07. Kiểm tra xem phương thức HTTP có phải là PATCH hay không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    08. Kiểm tra xem phương thức HTTP có phải là POST hay không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    09. Kiểm tra xem phương thức HTTP có phải là PURGE hay không (hỗ trợ Squid và Varnish)
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    10. Kiểm tra xem phương thức HTTP có phải là PUT không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    11. Kiểm tra xem yêu cầu đã được thực hiện bằng bất kỳ lớp bảo mật nào chưa
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    12. Kiểm tra xem yêu cầu đã được thực hiện bằng SOAP chưa
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    13. Kiểm tra xem phương thức HTTP có phải là TRACE không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    14. Kiểm tra xem một phương thức có phải là một phương thức HTTP hợp lệ không

kiểm tra sự tồn tại

Có một số phương thức có sẵn cho phép bạn kiểm tra sự tồn tại của các phần tử trong yêu cầu. Các phương thức này có tiền tố là

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
15. Tùy thuộc vào phương pháp được sử dụng, bạn có thể kiểm tra xem một phần tử có tồn tại trong bộ đệm
getQuery('userEmail');
0,
getQuery('userEmail');
8,
getQuery('userEmail', 'email', '[email protected]');
9,
getPost('userEmail');
5,
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
20, PUT và tiêu đề yêu cầu hay không

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    21. Kiểm tra xem siêu toàn cầu $_REQUEST có một phần tử nào đó không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    22. Kiểm tra xem yêu cầu có bất kỳ tệp đã tải lên nào không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    23. Kiểm tra xem các tiêu đề có một yếu tố nhất định
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    24. Kiểm tra xem $_POST superglobal có một phần tử nào đó không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    25. Kiểm tra xem dữ liệu PUT có một phần tử nào đó không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    26. Kiểm tra xem $_GET superglobal có một phần tử nào đó không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    27. Kiểm tra xem $_SERVER superglobal có một phần tử nào đó không
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    28. Trả về số lượng tệp có trong yêu cầu

Yêu cầu thông tin

Đối tượng cung cấp các phương thức cung cấp thông tin bổ sung liên quan đến yêu cầu

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    29. Nhận thông tin xác thực được trình duyệt/ứng dụng khách chấp nhận
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    30. Nhận thông tin xác thực được trình duyệt/ứng dụng khách chấp nhận

Khách hàng

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    31. Nhận địa chỉ IPv4 của khách hàng nhiều nhất có thể
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    32. Nhận một mảng bộ ký tự và chất lượng của chúng được trình duyệt/máy khách chấp nhận
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    33. Nhận tác nhân người dùng HTTP được sử dụng để thực hiện yêu cầu
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    34. Nhận trang web đề cập đến yêu cầu đang hoạt động

Nội dung

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    35. Nhận một mảng với mime/types và chất lượng của chúng được trình duyệt/client chấp nhận
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    36. Nhận kịch câm/loại tốt nhất được trình duyệt/máy khách chấp nhận
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    37. Nhận loại nội dung mà yêu cầu đã được thực hiện
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    38. Nhận phần thân yêu cầu thô JSON HTTP đã giải mã
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    39. Nhận nội dung yêu cầu thô HTTP

i18n

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    40. Nhận bộ ký tự tốt nhất được trình duyệt/máy khách chấp nhận
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    41. Nhận ngôn ngữ tốt nhất được trình duyệt/máy khách chấp nhận
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    42. Nhận mảng ngôn ngữ và chất lượng của chúng được trình duyệt/máy khách chấp nhận

Người phục vụ

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    43. Nhận thông tin về cổng mà yêu cầu được thực hiện
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    44. Nhận IP địa chỉ máy chủ đang hoạt động
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    45. Lấy tên máy chủ đang hoạt động
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    46. Nhận lược đồ HTTP (http/https)
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    47. Nhận HTTP URI mà yêu cầu đã được thực hiện. Nếu
    get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    48 được truyền dưới dạng tham số, phần truy vấn sẽ không được trả về

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
7

Một số phương pháp

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
8

Lấy địa chỉ IP của máy chủ. I E.

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
49

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
9

Lấy địa chỉ IP của khách hàng tức là.

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
50

get('userEmail');
0

Nhận tác nhân người dùng (

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
51)

get('userEmail');
1

Nhận nội dung được chấp nhận tốt nhất bởi trình duyệt. tức là văn bản/xml

get('userEmail');
2

Nhận bộ ký tự tốt nhất được trình duyệt chấp nhận. I E.

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
52

get('userEmail');
3

Nhận ngôn ngữ tốt nhất được chấp nhận cấu hình trong trình duyệt. I E.

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
53

Phương pháp

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
54 trả về phương thức HTTP mà yêu cầu đã được thực hiện. Nếu tiêu đề
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
55 được đặt và nếu phương thức là
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
56, thì nó được sử dụng để xác định phương thức HTTP dự định "thực". Tham số yêu cầu
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
57 cũng có thể được sử dụng để xác định phương thức HTTP,
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
58 đã được gọi. Phương thức luôn trả về một chuỗi chữ hoa

get('userEmail');
4

Tiêm phụ thuộc

Đối tượng thực hiện giao diện. Do đó, vùng chứa DI có sẵn và có thể được truy xuất bằng phương pháp

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
59. Một thùng chứa cũng có thể được đặt bằng phương thức
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
60

Tiêu đề yêu cầu chứa thông tin hữu ích, cho phép bạn thực hiện các bước cần thiết để gửi lại phản hồi thích hợp cho người dùng. Hiển thị các phương thức

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
61 và
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
62

get('userEmail');
5

Phương thức

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
63 sẽ trả về tên máy chủ được yêu cầu sử dụng. Phương pháp sẽ cố gắng tìm tên máy chủ theo thứ tự sau

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    64
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    65
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    66

Tùy chọn

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
63 xác thực và thực hiện kiểm tra nghiêm ngặt tên máy chủ. Để đạt được điều đó, bạn có thể sử dụng phương pháp
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
68

Tệp đã tải lên

Một tác vụ phổ biến khác là tải tệp lên. cung cấp một cách hướng đối tượng làm việc với các tập tin. Để toàn bộ quá trình tải lên hoạt động, bạn cần thực hiện các thay đổi cần thiết đối với

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
69 của mình (xem phần )

get('userEmail');
6

Mỗi đối tượng được trả về bởi

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
70 là một thể hiện của đối tượng thực hiện lớp. Sử dụng mảng siêu toàn cầu
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
20 cung cấp hành vi tương tự. chỉ gói gọn thông tin liên quan đến từng tệp được tải lên cùng với yêu cầu

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
72 chấp nhận hai tham số

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    73. Chỉ chứa các bản tải lên thành công
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    74. Trả về mảng có các khóa được đặt tên thu được trong quá trình tải lên

Phương thức trả về một mảng các đối tượng. Mỗi đối tượng cung cấp các thuộc tính và phương thức sau, cho phép bạn làm việc với các tệp đã tải lên

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    75 (chuỗi) - Trả về bất kỳ lỗi nào xảy ra với tệp này
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    76 (chuỗi) - Trả về phần mở rộng của tệp
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    77 (chuỗi) - Trả về khóa nội bộ của tệp
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    78 (chuỗi) -Trả về tên thật của tệp đã tải lên
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    79 (chuỗi) - Trả về loại kịch câm thực của tệp tải lên bằng finfo
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    80 (int) - Trả về kích thước tệp của tệp đã tải lên
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    81 (chuỗi) - Trả về tên tạm thời của tệp đã tải lên
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    82 (chuỗi) - Trả về loại mime do trình duyệt báo cáo. Loại kịch câm này không hoàn toàn an toàn, thay vào đó hãy sử dụng
    get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    79
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    84 (bool) - Kiểm tra xem tệp đã được tải lên qua
    get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    56
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    86 (bool) - Di chuyển tệp tạm thời đến đích trong ứng dụng

Tiêm phụ thuộc

Đối tượng thực hiện giao diện. Do đó, vùng chứa DI có sẵn và có thể được truy xuất bằng phương pháp

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
59. Một thùng chứa cũng có thể được đặt bằng phương thức
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
60

Sự kiện

Đối tượng thực hiện các giao diện. Kết quả là bạn có thể sử dụng

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
89 và
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
90

Sự kiện Mô tả Có thể dừng hoạt động
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
91Cháy khi ủy quyền đã được giải quyếtKhông
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
92Cháy trước khi ủy quyền đã được giải quyếtCó

Khi sử dụng ủy quyền HTTP, tiêu đề

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
93 có định dạng sau

get('userEmail');
7

trong đó

get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
94 là một loại xác thực. Một loại phổ biến là
get(
    $name = null,            // string
    $filters = null,         // mixed
    $defaultValue = null,    // mixed
    $notAllowEmpty = false,  // bool
    $noRecursive = false     // bool
): mixed
95. Các loại xác thực bổ sung được mô tả trong sổ đăng ký IANA về lược đồ xác thực và Xác thực cho máy chủ AWS (AWS4-HMAC-SHA256). Trong hầu hết các trường hợp sử dụng, loại xác thực là

  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    96
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    95
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    98
  • get(
        $name = null,            // string
        $filters = null,         // mixed
        $defaultValue = null,    // mixed
        $notAllowEmpty = false,  // bool
        $noRecursive = false     // bool
    ): mixed
    
    99
  • get('userEmail');
    
    00
  • get('userEmail');
    
    01
  • get('userEmail');
    
    02
  • get('userEmail');
    
    03
  • get('userEmail');
    
    04
  • get('userEmail');
    
    05
  • get('userEmail');
    
    06

Bạn có thể sử dụng các sự kiện

get('userEmail');
07 và
get('userEmail');
08 để thực hiện các thao tác bổ sung trước hoặc sau khi giải quyết ủy quyền

get('userEmail');
07 nhận mảng
get('userEmail');
10 với khóa
get('userEmail');
11 là tham số thứ hai của sự kiện

get('userEmail');
08 nhận mảng
get('userEmail');
10 với khóa
get('userEmail');
11 cũng như các tiêu đề với khóa
get('userEmail');
15

Làm cách nào để NHẬN yêu cầu HTTP trong PHP?

5 cách tạo yêu cầu HTTP trong PHP .
Trình bao bọc luồng HTTP/s của PHP
Phần mở rộng cURL của PHP
GuzzleHttp
Httpful
Máy khách HTTP của Symfony

Làm cách nào để kiểm tra HTTP hoặc HTTPS trong PHP?

Cách tiếp cận 1. Kiểm tra xem kết nối có đang sử dụng SSL hay không và nếu giá trị của $_SERVER['HTTPS'] được đặt, thì chúng tôi có thể nói rằng kết nối được bảo mật và được gọi từ 'HTTPS'. If the value is empty, this means the value is set to '0' or 'off' then we can say that the connection is not secured and the page is called from 'HTTP'.

Làm cách nào để NHẬN tiêu đề yêu cầu HTTP trong PHP?

Nhận được tiêu đề yêu cầu, máy chủ web sẽ gửi lại tiêu đề phản hồi HTTP cho máy khách. Đọc bất kỳ tiêu đề yêu cầu. Có thể đạt được điều này bằng cách sử dụng hàm getallheaders() . ví dụ 2. Nó có thể đạt được bằng cách sử dụng hàm apache_request_headers().

Tại sao chúng tôi sử dụng $request trong PHP?

PHP $_REQUEST là biến siêu toàn cầu PHP được sử dụng để thu thập dữ liệu sau khi gửi biểu mẫu HTML .