{"id":13669262,"url":"https://github.com/humbug/file_get_contents","last_synced_at":"2025-04-27T01:32:57.539Z","repository":{"id":26570417,"uuid":"30024579","full_name":"humbug/file_get_contents","owner":"humbug","description":"Secure wrapper for accessing HTTPS resources with file_get_contents() for PHP 5.3+.","archived":true,"fork":false,"pushed_at":"2018-02-12T18:48:11.000Z","size":41,"stargazers_count":124,"open_issues_count":5,"forks_count":15,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-13T13:03:14.299Z","etag":null,"topics":["php","security"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humbug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-29T14:47:50.000Z","updated_at":"2023-12-16T17:08:59.000Z","dependencies_parsed_at":"2022-08-31T17:00:13.218Z","dependency_job_id":null,"html_url":"https://github.com/humbug/file_get_contents","commit_stats":null,"previous_names":["padraic/file_get_contents"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humbug%2Ffile_get_contents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humbug%2Ffile_get_contents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humbug%2Ffile_get_contents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humbug%2Ffile_get_contents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humbug","download_url":"https://codeload.github.com/humbug/file_get_contents/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251077102,"owners_count":21532607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","security"],"created_at":"2024-08-02T08:01:07.953Z","updated_at":"2025-04-27T01:32:55.909Z","avatar_url":"https://github.com/humbug.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# humbug_get_contents\n\n[![Package version](https://img.shields.io/packagist/v/padraic/humbug_get_contents.svg?style=flat-square)](https://packagist.org/packages/padraic/humbug_get_contents)\n[![Build Status](https://img.shields.io/travis/humbug/file_get_contents.svg?branch=master\u0026style=flat-square)](https://travis-ci.org/humbug/file_get_contents?branch=master)\n[![Slack](https://img.shields.io/badge/slack-%23humbug-red.svg?style=flat-square)](https://symfony.com/slack-invite)\n[![License](https://img.shields.io/badge/license-MIT-red.svg?style=flat-square)](LICENSE)\n\nDefines a `Humbug\\get_contents()` function that will transparently call `file_get_contents()`,\nexcept for HTTPS URIs where it will inject a context configured to enable secure\nSSL/TLS requests on all versions of PHP 5.3+.\n\nAll versions of PHP below 5.6 not only disable SSL/TLS protections by default, but\nhave most other default options set insecurely. This has led to\nthe spread of insecure uses of `file_get_contents()` to retrieve HTTPS resources. For example,\nPHAR files or API requests. Without SSL/TLS protections, all such requests are vulnerable\nto Man-In-The-Middle attacks where a hacker can inject a fake response, e.g. a tailored php\nfile or json response.\n\n## Installation\n\n```bash\ncomposer require padraic/humbug_get_contents\n```\n\n\n## Usage\n\n```php\n$content = Humbug\\get_contents('https://www.howsmyssl.com/a/check');\n```\n\nYou can use this function as an immediate alternative to `file_get_contents()` in any code\nlocation where HTTP requests are probable.\n\nThis solution was originally implemented within the Composer Installer, so this is a\nstraightforward extraction of that code into a standalone package with just the one function.\nIt borrows functions from both Composer and Sslurp.\n\nIn rare cases, this function will complain when attempting to retrieve HTTPS URIs. This is\nactually the point ;). An error should have two causes:\n\n* A valid cafile could not be located, i.e. your server is misconfigured or missing a package\n* The URI requested could not be verified, i.e. in a browser this would be a red page warning.\n\nNeither is, in any way, a justification for disabling SSL/TLS and leaving end users vulnerable\nto getting hacked. Resolve such errors; don't ignore or workaround them.\n\n\n## Headers\n\nYou can set request headers, and get response headers, using the following functions.\nThis support is based around stream contexts, but is offered in some limited form\nhere as a convenience. If your needs are going to extend this, you should use a\nmore complete solution and double check that it fully enables and supports TLS.\n\n```php\n// Don't end headers with \\r\\n when setting via array\nHumbug\\set_headers([\n    'Accept-Language: da',\n    'User-Agent: Humbug',\n]);\n\n$response = Humbug\\get_contents('http://www.example.com');\n```\n\nRequest headers are emptied when used, so you would need to reset on each\n`Humbug\\get_contents()` call.\n\nTo retrieve an array of the last response headers:\n\n```php\n$response = Humbug\\get_contents('http://www.example.com');\n$headers = Humbug\\get_headers();\n```\n\n## Upgrade\n\n[Upgrade Guide](UPGRADE.md)\n\n\n## Contributing\n\n[Contribution Guide](CONTRIBUTING.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumbug%2Ffile_get_contents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumbug%2Ffile_get_contents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumbug%2Ffile_get_contents/lists"}