在 php 中生成 x-mod-nonce
Generate x-mod-nonce in php
根据我目前正在查看的一些文档,我需要将带有标签 x-mod-nonce 的 header 设置为每个请求的唯一值
示例 header:
x-mod-nonce: 28154b2-9c62b93cc22a-24c9e2-5536d7d
我想过用
uniqid 函数确实得到了这种类型的值,但我认为我不太理解它。
有人可以提示我如何做的一些例子或让我参考如何自己做吗?
I need to set a header with label x-mod-nonce to a unique value per request with example header
- 使用 random_bytes()
之类的内容生成您的 唯一值 字符串
- 将其连接到您的 header 字符串
将您的 header 设置为 header()
<?php
$unique_value = bin2hex(random_bytes(10));
header("x-mod-nonce: " . $unique_value);
您还可以设置一个与问题中提到的字符串具有类似模式的字符串,如下所示:
$pattern = bin2hex(random_bytes(10)) . "-" . bin2hex(random_bytes(10)) . "-" . bin2hex(random_bytes(10)) . "-" . bin2hex(random_bytes(10))
根据我目前正在查看的一些文档,我需要将带有标签 x-mod-nonce 的 header 设置为每个请求的唯一值 示例 header:
x-mod-nonce: 28154b2-9c62b93cc22a-24c9e2-5536d7d
我想过用 uniqid 函数确实得到了这种类型的值,但我认为我不太理解它。
有人可以提示我如何做的一些例子或让我参考如何自己做吗?
I need to set a header with label x-mod-nonce to a unique value per request with example header
- 使用 random_bytes() 之类的内容生成您的 唯一值 字符串
- 将其连接到您的 header 字符串
将您的 header 设置为 header()
<?php $unique_value = bin2hex(random_bytes(10)); header("x-mod-nonce: " . $unique_value);
您还可以设置一个与问题中提到的字符串具有类似模式的字符串,如下所示:
$pattern = bin2hex(random_bytes(10)) . "-" . bin2hex(random_bytes(10)) . "-" . bin2hex(random_bytes(10)) . "-" . bin2hex(random_bytes(10))