Request
The Request class provides a clean, unified interface for reading incoming HTTP request data
including input variables, headers, cookies, uploaded files, and URL information.
CSRF protection is automatically applied when enabled in your configuration.
The Request instance is available inside your controllers via $this->request.
Input Retrieval
These methods read values submitted with the request — from query strings, form bodies, or raw request bodies.
Retrieving a single value
Use input() to read a value from any source (GET, POST, or raw body) in one call:
<?php
// Returns the value of 'username' from any input source
$username = $this->request->input('username');
// With a default value if the key is missing
$page = $this->request->input('page', 1);
Retrieving typed values
Cast input directly to a specific type to avoid manual casting:
<?php
$id = $this->request->integer('id'); // int
$price = $this->request->float('price'); // float
$active = $this->request->boolean('active'); // bool
$name = $this->request->string('name'); // trimmed string
Retrieving by HTTP method
<?php
$name = $this->request->post('name'); // $_POST
$search = $this->request->get('q'); // $_GET
$title = $this->request->put('title'); // raw body (PUT)
$bio = $this->request->patch('bio'); // raw body (PATCH)
$confirm = $this->request->delete('confirm'); // raw body (DELETE)
Passing NULL (or no argument) returns the entire source array:
<?php
$all_post = $this->request->post(); // entire $_POST array
$all_get = $this->request->get(); // entire $_GET array
Default values
All retrieval methods accept a $default parameter:
<?php
$sort = $this->request->get('sort', 'asc');
$qty = $this->request->post('quantity', 1);
Fallback methods
<?php
// Checks POST first, then GET
$value = $this->request->post_get('search');
// Checks GET first, then POST
$value = $this->request->get_post('search');
All input at once
all() merges GET + POST + raw body into one array:
<?php
$data = $this->request->all();
Input method reference
Method |
Signature |
Description |
|---|---|---|
|
|
Read a value from any source (GET + POST + raw body) |
|
|
Read from |
|
|
Read from |
|
|
Read from raw body (PUT requests) |
|
|
Read from raw body (PATCH requests) |
|
|
Read from raw body (DELETE requests) |
|
|
POST with GET fallback |
|
|
GET with POST fallback |
|
|
All input merged (GET + POST + raw body) |
|
|
Input cast to |
|
|
Input cast to |
|
|
Input cast to |
|
|
Input cast to trimmed |
Filtering Input
Use these methods to select or exclude specific fields from the input.
<?php
// Only these keys
$data = $this->request->only(['name', 'email', 'password']);
// Everything except these keys
$data = $this->request->except(['csrf_token', '_method']);
Checking key presence
<?php
// TRUE only if ALL keys are present
if ($this->request->has(['name', 'email']))
{
// both exist
}
// TRUE if ANY of the keys are present
if ($this->request->has_any(['token', 'api_key']))
{
// at least one exists
}
// TRUE if present AND not empty
if ($this->request->filled('name'))
{
// name is present and has a non-empty value
}
// TRUE if the key is missing
if ($this->request->missing('optional_field'))
{
// not in the request
}
Method |
Signature |
Description |
|---|---|---|
|
|
All keys present (string or array) |
|
|
At least one key present |
|
|
Key present and value is not empty |
|
|
Key is not in the request |
|
|
Returns array with only the listed keys |
|
|
Returns array without the listed keys |
JSON & Raw Body
For API endpoints that receive a JSON body, use these methods:
<?php
// Decode the JSON body as an associative array
$data = $this->request->json();
// As an object
$data = $this->request->json(FALSE);
// Read the raw body string
$raw = $this->request->raw_body();
Note
json() returns NULL if the body is not valid JSON.
put(), patch(), and delete() also transparently decode JSON
when the Content-Type is application/json.
Method |
Signature |
Description |
|---|---|---|
|
|
Decode the JSON request body |
|
|
Return the raw body as a string |
File Uploads
Access uploaded files via the $_FILES superglobal through these methods:
<?php
// Check if a file was uploaded
if ($this->request->has_file('avatar'))
{
$file = $this->request->file('avatar');
// $file is the standard $_FILES['avatar'] array:
// ['name', 'type', 'tmp_name', 'error', 'size']
move_uploaded_file($file['tmp_name'], '/uploads/' . $file['name']);
}
// Get all uploaded files
$files = $this->request->files();
Method |
Signature |
Description |
|---|---|---|
|
|
Single |
|
|
Entire |
|
|
|
Headers
<?php
// Read a single header (case-insensitive)
$type = $this->request->header('Content-Type');
$token = $this->request->header('Authorization');
// Check if a header is present
if ($this->request->has_header('X-Api-Key'))
{
// header exists
}
// Read all headers as an associative array
$headers = $this->request->headers();
// Retrieve a Bearer token from the Authorization header
$token = $this->request->bearer_token();
// Returns the token string, or NULL if not a Bearer token
Method |
Signature |
Description |
|---|---|---|
|
|
Read a single header by name |
|
|
All request headers as an array |
|
|
|
|
|
Bearer token from |
HTTP Method
<?php
$method = $this->request->method(); // 'get', 'post', etc.
$method = $this->request->method(TRUE); // 'GET', 'POST', etc.
// Check against a specific method
if ($this->request->is_method('POST')) { ... }
if ($this->request->is_method(['PUT', 'PATCH'])) { ... }
// Convenience checkers
$this->request->is_get();
$this->request->is_post();
$this->request->is_put();
$this->request->is_patch();
$this->request->is_delete();
Note
If a POST request includes the X-HTTP-Method-Override header with a value of
PUT, PATCH, or DELETE, method() will return that overridden value.
This is useful for HTML forms that cannot send non-POST methods natively.
Method |
Signature |
Description |
|---|---|---|
|
|
Current HTTP method as string |
|
|
Compare against one or more methods |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Request Type Detection
<?php
$this->request->is_ajax(); // TRUE if X-Requested-With: XMLHttpRequest
$this->request->is_json(); // TRUE if Content-Type is application/json
$this->request->wants_json(); // TRUE if Accept header includes application/json
$this->request->is_secure(); // TRUE if request is over HTTPS
$this->request->is_mobile(); // TRUE if user agent matches a mobile device
Method |
Signature |
Description |
|---|---|---|
|
|
AJAX request check via |
|
|
Sending JSON ( |
|
|
Expects JSON response ( |
|
|
Request is over HTTPS |
|
|
User agent matches a mobile device |
URL & URI
<?php
$this->request->url(); // https://example.com/users?page=2
$this->request->url(FALSE); // https://example.com/users
$this->request->full_url_without_query(); // same as url(FALSE)
$this->request->uri(); // /users?page=2
$this->request->path(); // /users
$this->request->query_string(); // page=2
$this->request->query('page', 1); // '2' (from query string)
$this->request->host(); // example.com
$this->request->scheme(); // https
$this->request->port(); // 443
$this->request->referrer(); // previous page URL or NULL
Method |
Signature |
Description |
|---|---|---|
|
|
Full URL of the current request |
|
|
Full URL without the query string |
|
|
Request URI (path + query string) |
|
|
URI path without query string |
|
|
Raw query string (no leading |
|
|
Single query string parameter |
|
|
Hostname without port |
|
|
|
|
|
Server port as integer |
|
|
|
IP Address
<?php
// Direct IP (default, safe)
$ip = $this->request->ip_address();
// Trust proxy headers (only on servers behind a known proxy)
$ip = $this->request->ip_address(TRUE);
// Validate an IP
$this->request->valid_ip('192.168.1.1'); // TRUE
$this->request->valid_ip('192.168.1.1', 'ipv4'); // TRUE
$this->request->valid_ip('::1', 'ipv6'); // TRUE
$this->request->valid_ip('not-an-ip'); // FALSE
Warning
Only pass TRUE to ip_address() if your application is running behind
a trusted reverse proxy. Trusting client-supplied headers without verification
can allow IP spoofing.
Method |
Signature |
Description |
|---|---|---|
|
|
Client IP address |
|
|
Validate an IP ( |
Miscellaneous
<?php
$ua = $this->request->user_agent(); // User-Agent string or NULL
$srv = $this->request->server('SERVER_NAME'); // $_SERVER value
$all = $this->request->server(); // entire $_SERVER array
Method |
Signature |
Description |
|---|---|---|
|
|
|
|
|
Single |
Tips and Best Practices
Use
input()for general-purpose reads; usepost()/get()only when the source matters.Always use typed helpers (
integer(),boolean(),string()) before passing values to models or queries.Use
only()when passing request data directly to a model to avoid mass-assignment vulnerabilities.Prefer
filled()overhas()when an empty string should also be treated as absent.Use
bearer_token()for API authentication — never read theAuthorizationheader manually.Never trust
ip_address(TRUE)unless you control the proxy in front of your application.Use
is_json()to detect API clients andwants_json()to decide the response format.