PHPackages                             nanbando/humbug\_get\_contents - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. nanbando/humbug\_get\_contents

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nanbando/humbug\_get\_contents
==============================

Secure wrapper for accessing HTTPS resources with file\_get\_contents for PHP 5.3+

2.0.0(4y ago)071BSD-3-ClausePHPPHP ^5.3 || ^7.0 || ^7.1 || ^7.2 || ^8.0

Since Feb 4Pushed 4y agoCompare

[ Source](https://github.com/nanbando/file_get_contents)[ Packagist](https://packagist.org/packages/nanbando/humbug_get_contents)[ Docs](https://github.com/padraic/file_get_contents)[ RSS](/packages/nanbando-humbug-get-contents/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (4)Versions (10)Used By (1)

humbug\_get\_contents
=====================

[](#humbug_get_contents)

[![Package version](https://camo.githubusercontent.com/a7080f02c2ff492764695a77514c7a9ec3bcac206165a74f0bfd64199378af60/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706164726169632f68756d6275675f6765745f636f6e74656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/padraic/humbug_get_contents)[![Build Status](https://camo.githubusercontent.com/7a26aeb0ff1737374ac2149c2363158bce100d9c9b9bb25d8f4e30ccace60a20/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68756d6275672f66696c655f6765745f636f6e74656e74732e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.org/humbug/file_get_contents?branch=master)[![Slack](https://camo.githubusercontent.com/2f6358cd8cd3927356f9a75fc3b8fd8e83ce5bbad7f9efa4879e54f29780ebfb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736c61636b2d25323368756d6275672d7265642e7376673f7374796c653d666c61742d737175617265)](https://symfony.com/slack-invite)[![License](https://camo.githubusercontent.com/10e85a5778fe7601504a17ecd18dfa7097f473186b0f947bc10db2d3e4f530e4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d7265642e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Defines a `Humbug\get_contents()` function that will transparently call `file_get_contents()`, except for HTTPS URIs where it will inject a context configured to enable secure SSL/TLS requests on all versions of PHP 5.3+.

All versions of PHP below 5.6 not only disable SSL/TLS protections by default, but have most other default options set insecurely. This has led to the spread of insecure uses of `file_get_contents()` to retrieve HTTPS resources. For example, PHAR files or API requests. Without SSL/TLS protections, all such requests are vulnerable to Man-In-The-Middle attacks where a hacker can inject a fake response, e.g. a tailored php file or json response.

Installation
------------

[](#installation)

```
composer require padraic/humbug_get_contents
```

Usage
-----

[](#usage)

```
$content = Humbug\get_contents('https://www.howsmyssl.com/a/check');
```

You can use this function as an immediate alternative to `file_get_contents()` in any code location where HTTP requests are probable.

This solution was originally implemented within the Composer Installer, so this is a straightforward extraction of that code into a standalone package with just the one function. It borrows functions from both Composer and Sslurp.

In rare cases, this function will complain when attempting to retrieve HTTPS URIs. This is actually the point ;). An error should have two causes:

- A valid cafile could not be located, i.e. your server is misconfigured or missing a package
- The URI requested could not be verified, i.e. in a browser this would be a red page warning.

Neither is, in any way, a justification for disabling SSL/TLS and leaving end users vulnerable to getting hacked. Resolve such errors; don't ignore or workaround them.

Headers
-------

[](#headers)

You can set request headers, and get response headers, using the following functions. This support is based around stream contexts, but is offered in some limited form here as a convenience. If your needs are going to extend this, you should use a more complete solution and double check that it fully enables and supports TLS.

```
// Don't end headers with \r\n when setting via array
Humbug\set_headers([
    'Accept-Language: da',
    'User-Agent: Humbug',
]);

$response = Humbug\get_contents('http://www.example.com');
```

Request headers are emptied when used, so you would need to reset on each `Humbug\get_contents()` call.

To retrieve an array of the last response headers:

```
$response = Humbug\get_contents('http://www.example.com');
$headers = Humbug\get_headers();
```

Upgrade
-------

[](#upgrade)

[Upgrade Guide](UPGRADE.md)

Contributing
------------

[](#contributing)

[Contribution Guide](CONTRIBUTING.md)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~291 days

Recently: every ~563 days

Total

9

Last Release

1785d ago

Major Versions

1.1.2 → 2.0.02021-06-23

PHP version history (4 changes)1.0.0PHP &gt;=5.3

1.1.0PHP ^5.3 || ^7.0

1.1.2PHP ^5.3 || ^7.0 || ^7.1 || ^7.2

2.0.0PHP ^5.3 || ^7.0 || ^7.1 || ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e43a10984e8ee1687abaac86c26311c6a607b9560e8a3cc3193f8245751618bc?d=identicon)[wachterjohannes](/maintainers/wachterjohannes)

---

Top Contributors

[![padraic](https://avatars.githubusercontent.com/u/19780?v=4)](https://github.com/padraic "padraic (25 commits)")[![theofidry](https://avatars.githubusercontent.com/u/5175937?v=4)](https://github.com/theofidry "theofidry (8 commits)")[![wachterjohannes](https://avatars.githubusercontent.com/u/1464615?v=4)](https://github.com/wachterjohannes "wachterjohannes (3 commits)")[![thewilkybarkid](https://avatars.githubusercontent.com/u/1784740?v=4)](https://github.com/thewilkybarkid "thewilkybarkid (1 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![kelunik](https://avatars.githubusercontent.com/u/2743004?v=4)](https://github.com/kelunik "kelunik (1 commits)")

---

Tags

httphttpstlsssldownloadfile\_get\_contents

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nanbando-humbug-get-contents/health.svg)

```
[![Health](https://phpackages.com/badges/nanbando-humbug-get-contents/health.svg)](https://phpackages.com/packages/nanbando-humbug-get-contents)
```

###  Alternatives

[padraic/humbug_get_contents

Secure wrapper for accessing HTTPS resources with file\_get\_contents for PHP 5.3+

1255.3M5](/packages/padraic-humbug-get-contents)[league/uri

URI manipulation library

1.1k206.4M277](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)[mashape/unirest-php

Unirest PHP

1.3k9.7M161](/packages/mashape-unirest-php)[aplus/http

Aplus Framework HTTP Library

2311.6M10](/packages/aplus-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
