gpt4 book ai didi

php - header 中的 AuthKey

转载 作者:可可西里 更新时间:2023-11-01 13:24:10 25 4
gpt4 key购买 nike

所以我的客户需要一个使用 PHP 的 REST API,它根据 URL 参数的条件提供输出

现在基本上需要三个 URL,它们已经完成。

他们是

localhost/newapi/client/<AuthKey> - for authorizing

localhost/newapi/client/<clientid>/categories/ - to get all the categories

localhost/newapi/client/<clientid>/categories/<categoryid> - to get all items in a category

将 .htaccess 用于精美的 URL

所以现在他要求需要将 AuthKey 添加到 HTTP header 而不是 URL。所以 AuthKey 必须作为 header 传递,其余作为 URL 参数传递

所以我的问题是如何做到这一点。以及如何从请求中检索 AuthKey?

欢迎任何关于这个问题的教程或评论

最佳答案

您可以在客户请求您的 api 时告诉他添加如下 header :

AuthKey:你的-api-auth-key
或者
token :您的 API token

然后在你的 php 代码中做

$headers = getallheaders();
$token = $headers['Token'] or ['AuthKey'];

然后你检查数据库中的 key 然后处理你的代码

注意:
您的客户可以使用 PHP cURL 添加 header

curl_setopt($curl-handle, CURLOPT_HEADER, array(
'Token' => 'client-auth-token', //or
'AuthKey' => 'client-auth-token'
));

关于php - header 中的 AuthKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30432132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com