使用file_get_contents进行身份验证和访问htaccess保护的文件 [英] using file_get_contents to authenticate and access an htaccess protected file

查看:66
本文介绍了使用file_get_contents进行身份验证和访问htaccess保护的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问一个受常规.htaccess文件保护的国外.php页面(Auth类型为Basic,htpasswords等)。

I need to reach a foreign .php page protected by a regular .htaccess file (Auth type Basic, htpasswords etc...).

我想要通过请求发送所需的用户和密码。可能吗?我想避免使用 cURL 和所有 pecl_http 依赖的函数...

I'd like to send the user and password needed through the request. Is it possible? I would like to avoid cURL and all pecl_http dependent functions if possible...

推荐答案

即席,我相信您可以使用上下文来做到这一点:

Off-hand, I believe you can use a context to do that:

$context = stream_context_create(array (
    'http' => array (
        'header' => 'Authorization: Basic ' . base64_encode("$username:$password")
    )
));
$data = file_get_contents($url, false, $context);

这篇关于使用file_get_contents进行身份验证和访问htaccess保护的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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