{"id":21074033,"url":"https://github.com/hugsbrugs/php-http","last_synced_at":"2025-03-14T03:24:58.235Z","repository":{"id":37587603,"uuid":"84943169","full_name":"hugsbrugs/php-http","owner":"hugsbrugs","description":"PHP HTTP Utilities","archived":false,"fork":false,"pushed_at":"2023-04-19T19:24:33.000Z","size":292,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-21T16:19:45.635Z","etag":null,"topics":["http","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hugsbrugs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-14T11:49:56.000Z","updated_at":"2022-03-01T10:00:26.000Z","dependencies_parsed_at":"2022-08-21T13:20:21.099Z","dependency_job_id":null,"html_url":"https://github.com/hugsbrugs/php-http","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugsbrugs%2Fphp-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugsbrugs%2Fphp-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugsbrugs%2Fphp-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugsbrugs%2Fphp-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hugsbrugs","download_url":"https://codeload.github.com/hugsbrugs/php-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243516850,"owners_count":20303520,"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":["http","php"],"created_at":"2024-11-19T19:14:14.897Z","updated_at":"2025-03-14T03:24:58.214Z","avatar_url":"https://github.com/hugsbrugs.png","language":"PHP","readme":"# php-http\n\nThis library provides PHP utilities functions to manage URLs. Read [PHP DOC](https://hugsbrugs.github.io/php-http)\n\n[![Build Status](https://travis-ci.org/hugsbrugs/php-http.svg?branch=master)](https://travis-ci.org/hugsbrugs/php-http)\n[![Coverage Status](https://coveralls.io/repos/github/hugsbrugs/php-http/badge.svg?branch=master)](https://coveralls.io/github/hugsbrugs/php-http?branch=master)\n\n## Install\n\nInstall package with composer\n```\ncomposer require hugsbrugs/php-http\n```\n\nIn your PHP code, load librairy\n```php\nrequire_once __DIR__ . '/../vendor/autoload.php';\nuse Hug\\Http\\Http as Http;\n```\n\n## Configuration\n\nIn order to use cache mechanism, define following constants\n```php\ndefine('PDP_PDO_DSN', 'mysql:host=localhost;dbname=database');\ndefine('PDP_PDO_USER', 'username');\ndefine('PDP_PDO_PASS', 'password');\ndefine('PDP_PDO_OPTIONS', [PDO::ATTR_ERRMODE =\u003e PDO::ERRMODE_EXCEPTION]);\n```\n\nAlternatively define path to the local stored [public suffix list](https://publicsuffix.org/list/public_suffix_list.dat)\n```php\ndefine('PUBLIC_SUFFIX_LIST', realpath(__DIR__ . '/../../../cache/public_suffix_list.dat'));\n```\nThis method should not be used in production since it's really slow.\n\nOtherwise the default, not accurate, cache/public_suffix_list.dat file will be used.\n\n## Usage\n\nExecute shell nslookup command\n```php\nHttp::nslookup($url);\n```\n\nCheck if an url is accessible (means not a 404)\n```php\nHttp::is_url_accessible($url);\n```\n\nReturns HTTP code for given URL\n```php\nHttp::get_http_code($url);\n```\n\nCleans an url from its query parameters\n```php\nHttp::url_remove_query($url);\n```\n\nCleans an url from its query parameters and path\n```php\nHttp::url_remove_query_and_path($url);\n```\n\nQuick and dirty function to save an image from the internet\n```php\nHttp::grab_image($url, $save_to);\n```\n\nReturns basic HTTP headers for a CURL request\n```php\nHttp::get_default_headers($host);\n```\n\nExtracts suffix, tld, domain and subdomain from an URL\n```php\nHttp::extract_all_from_url($url);\n```\n\nExtracts extention from an URL\n```php\nHttp::extract_extension_from_url($url);\n```\n\nExtracts scheme (ftp, http) from an URL\n```php\nHttp::extract_scheme_from_url($url);\n```\n\nExtracts a TLD (Top Level Domain) from an URL\n```php\nHttp::extract_tld_from_url($url);\n```\n\nExtracts a sub domain from an URL\n```php\nHttp::extract_subdomain_from_url($url);\n```\n\nExtracts a domain name from an URL\n```php\nHttp::extract_domain_from_url($url);\n```\n\nSeparates Headers from Body in CURL response\n```php\nHttp::extract_request_headers_body($html_with_headers);\n```\n\nSets a php script desired status code (usefull for API)\n```php\nHttp::header_status($statusCode);\n```\n\nGets the address and/or http code that the provided URL redirects to. $return can be : url/code/all\n```php\nHttp::get_redirect_url($url, $timeout = 5, $return = 'url');\n```\n\nFollows and collects all redirects, in order, for the given URL.\n```php\nHttp::get_all_redirects($url);\n```\n\nGets the address and/or http code that the URL ultimately leads to. $return can be : url/code/all\n```php\nHttp::get_final_url($url, $return = 'url');\n```\n\nCheck a TXT record in domain zone file\n```php\nHttp::check_txt_record($domain, $txt);\n```\n\nWaits and tests every minute if domain zone has correct IP adress and TXT record set\n```php\nHttp::wait_for_zone_ok($domain, $ip, $txt_record, $wait_minutes = 15);\n```\n\nTests if domain zone has correct IP adress and TXT record set\n```php\nHttp::is_zone_ok($domain, $ip, $txt_record);\n```\n\nGet name servers of given domain\n```php\nHttp::get_name_servers('maugey.fr');\n```\n\nAdd escaped fragment to URL\n```php\nHttp::add_escaped_fragment($url);\n```\n\nTo enable CORS, put this line at top of your PHP script\n```php\nHttp::cors();\n```\n\nConverts an URL to a filename\nIt does not encode URL parameters (only scheme - domain - folders - file)\n```php\nHttp::url_2_filename($url);\n```\n\n## Dependecies\nhttps://github.com/jeremykendall/php-domain-parser\nhttps://github.com/jeremykendall/php-domain-parser/tree/5.7.0\nhttps://publicsuffix.org/list/public_suffix_list.dat\n\n\n## Unit Tests\n\n```\ncomposer exec phpunit\nphpunit --configuration phpunit.xml\n```\n\n## Author\n\nHugo Maugey [Webmaster](https://hugo.maugey.fr/webmaster) | [Consultant SEO](https://hugo.maugey.fr/consultant-seo) | [Fullstack developer](https://hugo.maugey.fr/developpeur-web)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugsbrugs%2Fphp-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugsbrugs%2Fphp-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugsbrugs%2Fphp-http/lists"}