Fuel Documentation

Input Class

The input class allows you to access HTTP parameters, load server variables and user agent details.

detect_uri()

The detect_uri method detects the current URI to build the correct string.

Static Yes
Parameters None
Returns string
Example
// Example URL: http://localhost/controller/method
echo Input::detect_uri(); // returns controller/method

The cookie method allows you to read $_COOKIE variables. Call without params to fetch the full cookie array.

Static Yes
Parameters
Param Default Description
$index optional The key in the $_COOKIE array. Multi-dimensional arrays can be accessed by separating the levels by a dot (.)
$default
null
What value should be returned if the array item is not found?
Returns mixed
Example
Input::cookie('foo', 'bar');

delete($index, $default = null)

The delete method allows you to read parameters from php://input stream when called via DELETE. Call without params to fetch the full array.

Static Yes
Parameters
Param Default Description
$index optional The key in the php://input stream.
$default optional What value should be returned if the array item is not found?
Returns mixed
Example
Input::delete('foo', 'bar');

put($index, $default = null)

The put method allows you to read parameters from php://input stream when called via PUT. Call without params to fetch the full array.

Static Yes
Parameters
Param Default Description
$index optional The key in the php://input stream.
$default optional What value should be returned if the array item is not found?
Returns mixed
Example
Input::put('foo', 'bar');

get($index, $default = null)

The get method allows you to read $_GET variables. Call without params to fetch the full array.

Static Yes
Parameters
Param Default Description
$index required The key in the $_GET array. Multi-dimensional arrays can be accessed by separating the levels by a dot (.)
$default optional What value should be returned if the array item is not found?
Returns mixed
Example
Input::get('foo', 'bar');

// You can go multiple levels deep as well.
// This will return $_GET['somevar']['foo']['bar']
Input::get('somevar.foo.bar');

post($index, $default = null)

The post method allows you to read $_POST variables. Call without params to fetch the full array.

Static Yes
Parameters
Param Default Description
$index optional The key in the $_POST array. Multi-dimensional arrays can be accessed by separating the levels by a dot (.)
$default optional What value should be returned if the array item is not found?
Returns mixed
Example
Input::post('foo', 'bar');

// You can go multiple levels deep as well.
// This will return $_POST['somevar']['foo']['bar']
Input::post('somevar.foo.bar');

get_post($index, $default = null)

The get_post method allows you to read from $_GET and $_POST variables, checking $_GET first.

Static Yes
Parameters
Param Default Description
$index required The key in the $_GET or $_POST array. Multi-dimensional arrays can be accessed by separating the levels by a dot (.)
$default optional What value should be returned if the array item is not found?
Returns mixed
Example
Input::get_post('foo', 'bar');

is_ajax()

The is_ajax method returns true if the controller is called via AJAX.

Static Yes
Parameters None
Returns mixed
Example
Input::is_ajax(); // false

method()

The method method returns the HTTP method used to call the controller.

Static Yes
Parameters None
Returns string
Example
Input::method(); // "GET"

protocol()

The protocol method returns the HTTP protocol used to call the controller.

Static Yes
Parameters None
Returns string
Example
Input::protocol(); // "HTTP"

ip()

The ip method returns the public IP address of the user. If the user operates from behind a proxy server, the IP address of that server is returned.

Static Yes
Parameters None
Returns string
Example
echo Input::ip(); // 73.194.37.104 (public IP address)

real_ip()

The real_ip method returns the 'real' IP address of the user. If a proxy server is detected, it will attempt to determine the user's private IP address from the information the proxy adds to the header. If this information is not present, the public IP address is returned.

Static Yes
Parameters None
Returns string
Example
echo Input::real_ip(); // 10.76.12.199 (private IP behind a proxy server)

server($index, $default = null)

The server method allows you to read parameters from the $_SERVER array with default values. Call without params to fetch the full array.

Static Yes
Parameters
Param Default Description
$index optional The key in the $_SERVER array.
$default optional What value should be returned if the array item is not found?
Returns string
Example
Input::server('HTTP_HOST'); // "localhost:8080"