Introduction
In this article I describe the PHP miscelaneous functions connection_abroted, connection_status, constant, define and defined, so the following function were paced in the Miscellaneous category because none of the other categories seemed to fit.
PHP connection_abroted() Function
The PHP miscelaneous connection_aborted function is used to check whether the client is disconnected and it returns 1 (one) if the client was disconnected otherwise it returns 0 (zero).
Syntax
Example
An example of the function is:
<?php
function checkAbort()
{
if (connection_aborted())
error_log ("Script $GLOBALS[SCRIPT_NAME]" .
"$GLOBALS[SERVER_NAME] was aborted by the user.");
}
register_shutdown_function("checkAbort");
?>
PHP connection_status() Function
The PHP miscelaneous connection_status function returns a connection status bit field and the possible return values are:
- 0-CONNECTION_NORMAL
- 1-CONNECTION_ABORTED
- 2-CONNECTION_TIMEOUT
- 3-CONECTION_ABROTED & CONNECTION_TIMEOUT
Syntax
Example
An example of the function is:
<?php
switch (connection_status ())
{
case CONNECTION_NORMAL:
$data = 'Now Connection is in a normal state';
break;
case CONNECTION_ABORTED:
$data = 'Connection aborted';
break;
case CONNECTION_TIMEOUT:
$data = 'Connection timed out';
break;
case (CONNECTION_ABORTED & CONNECTION_TIMEOUT):
$data = 'Connection aborted and timed out';
break;
default:
$data = 'Unknown';
break;
}
echo $data;
?>
Output
PHP constant() Function
The PHP miscelaneous constant function returns the value of a constant or say it returns the value of a constant on success or NULL if the constant is not defined.
Syntax
Parameter in constant function
The parameter of the function is:
Parameter |
Description |
constant |
It specifies the name of the constant to check. |
Example
<?php
define("C-ShapCorner","Welcome at MCN Solution!");
echo constant("C-ShapCorner");
?>
Output
PHP define() Function
The PHP miscelaneous define function defines the name of a constant and it returns TRUE on success or FALSE on failure.
Syntax
define(name, value,CaseInsensitive) |
Parameter in define function
The parameters of the function are:
Parameter |
Description |
name |
It specifies the name of the constant. |
value |
It specifies the value of the constant. |
CaseInsensitive |
It specifies whether the constant name should be case-insensitive. |
Example
<?php
define("C-ShapCorner","Welcome at MCN Solution!");
echo constant("C-ShapCorner");
?>
Output
PHP defined() Function
The PHP miscelaneous defined function checks whether a constant exists and it returns true if the constant exists or false on failure.
Syntax
Parameter in defined function
The parameter of the function is:
Parameter |
Description |
name |
It specifies the name of the constant to check. |
Example
<?php
define("C-ShapCorner","Welcome at MCN Solution!");
echo defined("C-ShapCorner");
?>
Output