-
Notifications
You must be signed in to change notification settings - Fork 1
ServerRequest: getAttributes Example
Terry L edited this page Jun 18, 2020
·
3 revisions
Extends Request.
-
return
array
Example:
$_SESSION['user_name'] = 'terrylin';
$_SESSION['user_role'] = 'admin';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$serverRequest = $serverRequest->
withAttribute('session', $_SESSION)->
withAttribute('ip_address', $_SERVER['REMOTE_ADDR']);
$attributes = $serverRequest->getAttributes();
echo $attributes['session']['user_name'];
// Outputs: terrylin
echo $attributes['ip_address'];
// Outputs: 127.0.0.1composer require shieldon/psr-httpShieldon PSR HTTP implementation written by Terry L. from Taiwan.
