Skip to content

Core\Ldap\Sid::toString

$sid->toString(): string

Returns the SID as text, such as S-1-5-32-544.

Use it to show a SID to a person, to write it to a log, or to use it as a key in an array. Sid::parse reads the text back as the same SID.

Good to know: the authority is written as a decimal number. Only an authority of 4294967296 or more is written in hex, with 0x, as Windows does.

Return value

Returns string. The text. Sid::parse reads it back as the same SID.

Examples

Show a sid

<?nvs
// Shows how to print a SID as text.
var $everyone = Core\Ldap\Sid::parse('S-1-1-0');
// This prints S-1-1-0.
echo $everyone->toString(), "\n";
Output
S-1-1-0

Sid in a message

<?nvs
// Shows how to put the text of a SID into a log message.
var $user = Core\Ldap\Sid::parse('S-1-5-21-1004336348-1177238915-682003330-1105');
string $message = 'Account ' . $user->toString() . ' logged in';
// This prints the message with the full SID in it.
echo $message, "\n";
Output
Account S-1-5-21-1004336348-1177238915-682003330-1105 logged in

Hex authority

<?nvs
// Shows how `toString` writes the authority, the number after `S-1-`.
// A small authority is written in decimal, even when the text used hex.
echo Core\Ldap\Sid::parse('S-1-0x000000000005-7')->toString(), "\n";
// A large authority is written in hex. This prints S-1-0x010000000000-7.
echo Core\Ldap\Sid::parse('S-1-0x010000000000-7')->toString(), "\n";
Output
S-1-5-7
S-1-0x010000000000-7