Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F24683469
core.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
core.php
View Options
<?php
namespace
Keruald
;
/**
* Keruald, core libraries for Pluton and Xen engines.
*
* Global functions
*/
///
/// Error and debug
///
/**
* Prints human-readable information about a variable, wrapped in a <pre> block
*
* @param mixed $variable the variable to dump
*/
function
dprint_r
(
$variable
)
{
echo
'<pre>'
;
print_r
(
$variable
);
echo
'</pre>'
;
}
/**
* Prints human-readable information about a variable, wrapped in a <pre> block
* then dies
*
* @param mixed $variable the variable to dump
*/
function
dieprint_r
(
$variable
)
{
dprint_r
(
$variable
);
die
;
};
///
/// Client information
///
/**
* Returns the full header or the IP part of it
*
* @param string $value The header value
* @return string the IP part
*/
function
extract_client_ip_from_header
(
$value
)
{
if
(
strpos
(
$value
,
','
)
!==
false
)
{
//Header contains 'clientIP, proxyIP, anotherProxyIP'
//The first value is so the one to return.
//See draft-ietf-appsawg-http-forwarded-10.
$ips
=
explode
(
','
,
$value
,
2
);
return
trim
(
$ips
[
0
]);
}
return
$value
;
}
/**
* Gets remote IP address.
*
* This is intended as a drop-in replacement for $_SERVER['REMOTE_ADDR'],
* which takes in consideration proxy values.
*/
function
get_remote_addr
()
{
$candidates
=
[
//Standard header provided by draft-ietf-appsawg-http-forwarded-10
'HTTP_X_FORWARDED_FOR'
,
//Legacy headers
'HTTP_CLIENT_IP'
,
'HTTP_FORWARDED'
,
'HTTP_FORWARDED_FOR'
,
'HTTP_X_CLUSTER_CLIENT_IP'
,
'HTTP_X_FORWARDED'
,
//Default header if no proxy information could be detected
'REMOTE_ADDR'
,
];
foreach
(
$candidates
as
$candidate
)
{
if
(
array_key_exists
(
$candidate
,
$_SERVER
))
{
return
extract_client_ip_from_header
(
$_SERVER
[
$candidate
]);
}
}
return
''
;
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Mar 7, 02:58 (20 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3449159
Default Alt Text
core.php (1 KB)
Attached To
Mode
rKGF Keruald global functions
Attached
Detach File
Event Timeline
Log In to Comment