QueryString
in package
Uses
BackwardCompatibility
Handles the query string, request variables, and session management.
Table of Contents
Properties
- $backcompat : array<string|int, mixed>
Methods
- cleanRequest() : void
- Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- isFilteredRequest() : bool
- Checks whether a $_REQUEST variable contains an expected value.
- matchIPtoCIDR() : bool
- Detect if a IP is in a CIDR address.
- ob_sessrewrite() : string
- Rewrite URLs to include the session ID.
Properties
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['cleanRequest' => 'cleanRequest', 'isFilteredRequest' => 'is_filtered_request', 'ob_sessrewrite' => 'ob_sessrewrite', 'matchIPtoCIDR' => 'matchIPtoCIDR']]
BackwardCompatibility settings for this class.
Methods
cleanRequest()
Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
public
static cleanRequest() : void
What it does:
- cleans the request variables (ENV, GET, POST, COOKIE, SERVER) and
- makes sure the query string was parsed correctly.
- handles the URLs passed by the queryless URLs option.
- makes sure, regardless of php.ini, everything has slashes.
- sets up Board::$board_id, Topic::$topic_id, and $_REQUEST['start'].
- determines, or rather tries to determine, the client's IP.
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.
Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
isFilteredRequest()
Checks whether a $_REQUEST variable contains an expected value.
public
static isFilteredRequest(array<string|int, mixed> $value_list, string $var) : bool
The second paramenter, $var, gives the name of the $_REQUEST variable to check. For example, if $var == 'action', then $_REQUEST['action'] will be tested.
The first parameter, $value_list, is an associative array whose keys denote accepted values in $_REQUEST[$var], and whose values can be:
-
Null, in which case the existence of $_REQUEST[$var] causes the test to fail.
-
A non-null scalar value, in which case the existence of $_REQUEST[$var] is all that is necessary to pass the test.
-
Another associative array indicating additional $_REQUEST variables and acceptable values that must also be present.
For example, if $var == 'action' and $value_list contains this:
'logout' => true,
'pm' => array('sa' => array('popup')),
... then the test will pass (a) if $_REQUEST['action'] == 'logout' or (b) if $_REQUEST['action'] == 'pm' and $_REQUEST['sa'] == 'popup'.
Parameters
- $value_list : array<string|int, mixed>
-
A list of acceptable values.
- $var : string
-
Name of a $_REQUEST variable.
Return values
bool —Whether any of the criteria were satisfied.
matchIPtoCIDR()
Detect if a IP is in a CIDR address.
public
matchIPtoCIDR(string $ip_address, string $cidr_address) : bool
Parameters
- $ip_address : string
-
IP address to check.
- $cidr_address : string
-
CIDR address to verify.
Return values
bool —Whether the IP matches the CIDR.
ob_sessrewrite()
Rewrite URLs to include the session ID.
public
static ob_sessrewrite(string $buffer) : string
What it does:
- rewrites the URLs outputted to have the session ID, if the user is not accepting cookies and is using a standard web browser.
- handles rewriting URLs for the queryless URLs option.
- can be turned off entirely by setting Config::$scripturl to an empty string, ''. (it wouldn't work well like that anyway.)
- because of bugs in certain builds of PHP, does not function in versions lower than 4.3.0 - please upgrade if this hurts you.
Parameters
- $buffer : string
-
The unmodified output buffer.
Return values
string —The modified buffer.