如何使用授权头PHP [英] How to use authorization header PHP

查看:233
本文介绍了如何使用授权头PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,以使用VIMEO API来使用授权头。

它告诉我做这个授权:基本'+的base64(CLIENT_ID +:+ client_secret),这是我能够做到的。

但无处在互联网上它告诉我,其实我这个code呢?这不是PHP,但它在一个PHP文件中去?如果是这样的话我就可以使用什么函数存储后?是否在htaccess文件去了?

这是很可悲的任何及所有在线文档如何可怕的是这一点。

要总结,基本上是即时消息说是给我code

感谢您的帮助。


解决方案

  $ api_url =的http:// myapiurl';$ CLIENT_ID ='myclientid';
$ client_secret ='myclientsecret';$语境= stream_context_create(阵列(
    'HTTP'=>阵列(
        '头'=> 授权:基本。 base64_en code($ CLIENT_ID:$ client_secret),
    )
));$结果=的file_get_contents($ api_url,虚假,$背景);

http://php.net/file_get_contents

http://php.net/stream_context_create

有关更复杂的要求,则可以使用卷曲,但它是一个烂摊子,我preFER避免其时,我可以。

I am trying to use an authorization header in order to use the vimeo API.

It tells me to do this 'Authorization: basic ' + base64(client_id + ':' + client_secret) , which is something I can do.

But nowhere on the internet does it tell me what I actually do with this code? It is not PHP, but does it go in a PHP file? If so then what function do I use on it after storing it? Does it go in an htaccess file?

It is really sad how terrible any and all online documentation is on this.

To summarize, basically what im saying is SHOW ME THE CODE

Thanks for the help

解决方案

$api_url = 'http://myapiurl';

$client_id = 'myclientid';
$client_secret = 'myclientsecret';

$context = stream_context_create(array(
    'http' => array(
        'headers' => "Authorization: Basic " . base64_encode("$client_id:$client_secret"),
    ),
));

$result = file_get_contents($api_url, false, $context);

http://php.net/file_get_contents

http://php.net/stream_context_create

For more complex requests, you can use cURL, but it's a mess and I prefer to avoid it when I can.

这篇关于如何使用授权头PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆