-
Notifications
You must be signed in to change notification settings - Fork 1
ServerRequest: getAttributes Example
Terry L edited this page Jun 20, 2020
·
3 revisions
Shieldon\Psr7\ServerRequest
Extends Request.
Retrieve attributes derived from the 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.1
composer require shieldon/psr-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.