首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

OAuthProvider::generateToken

(PECL OAuth >= 1.0.0)

OAuthProvider::generateToken — Generate a random token

Description

代码语言:javascript
复制
final public static string OAuthProvider::generateToken ( int $size [, bool $strong = false ] )

Generates a string of pseudo-random bytes.

Parameters

size

The desired token length, in terms of bytes.

strong

Setting to TRUE means /dev/random will be used for entropy, as otherwise the non-blocking /dev/urandom is used. This parameter is ignored on Windows.

Return Values

The generated token, as a string of bytes.

Errors/Exceptions

If the strong parameter is TRUE, then an E_WARNING level error will be emitted when the fallback rand() implementation is used to fill the remaining random bytes (e.g., when not enough random data was found, initially).

Examples

Example #1 OAuthProvider::generateToken() example

代码语言:javascript
复制
<?php
$p = new OAuthProvider();

$t = $p->generateToken(4);

echo strlen($t),  PHP_EOL;
echo bin2hex($t), PHP_EOL;

?>

The above example will output something similar to:

代码语言:javascript
复制
4
b6a82c27

Notes

Note: When not enough random data is available to the system, this function will fill the remaining random bytes using the internal PHP rand() implementation.

See Also

  • openssl_random_pseudo_bytes() - Generate a pseudo-random string of bytes
  • mcrypt_create_iv() - Creates an initialization vector (IV) from a random source

← OAuthProvider::consumerHandler

OAuthProvider::is2LeggedEndpoint →

代码语言:txt
复制
 © 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券