{"id":18656269,"url":"https://github.com/bayfrontmedia/php-http-request","last_synced_at":"2025-07-17T20:33:42.970Z","repository":{"id":62492273,"uuid":"283009647","full_name":"bayfrontmedia/php-http-request","owner":"bayfrontmedia","description":"Easily handle data from incoming HTTP requests.","archived":false,"fork":false,"pushed_at":"2024-12-25T12:25:44.000Z","size":50,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T20:51:38.482Z","etag":null,"topics":["cookie","delete","get","head","header","http","method","options","patch","php","post","put","request","server","superglobal","url"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bayfrontmedia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-07-27T20:32:19.000Z","updated_at":"2024-12-25T12:25:24.000Z","dependencies_parsed_at":"2024-09-10T04:37:23.790Z","dependency_job_id":"bf12fbc4-1f31-4e6a-9eaf-b0b312110dda","html_url":"https://github.com/bayfrontmedia/php-http-request","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"922d194ab7e4861c83ead36ed88a91812e71e05d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/bayfrontmedia/php-http-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bayfrontmedia","download_url":"https://codeload.github.com/bayfrontmedia/php-http-request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-request/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265659157,"owners_count":23806875,"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":["cookie","delete","get","head","header","http","method","options","patch","php","post","put","request","server","superglobal","url"],"created_at":"2024-11-07T07:22:45.177Z","updated_at":"2025-07-17T20:33:42.918Z","avatar_url":"https://github.com/bayfrontmedia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PHP HTTP request\n\nEasily handle data from incoming HTTP requests.\n\n- [License](#license)\n- [Author](#author)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n\n## Author\n\n\u003cimg src=\"https://cdn1.onbayfront.com/bfm/brand/bfm-logo.svg\" alt=\"Bayfront Media\" width=\"250\" /\u003e\n\n- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github\u0026amp;utm_medium=direct)\n- [Bayfront Media GitHub](https://github.com/bayfrontmedia)\n\n## Requirements\n\n- PHP `^8.0` (Tested up to `8.4`)\n\n## Installation\n\n```\ncomposer require bayfrontmedia/php-http-request\n```\n\n## Usage\n\n**Request methods**\n\n- [validateMethod](#validatemethod)\n- [getMethod](#getmethod)\n- [isConnect](#isconnect)\n- [isDelete](#isdelete)\n- [isGet](#isget)\n- [isHead](#ishead)\n- [isOptions](#isoptions)\n- [isPatch](#ispatch)\n- [isPost](#ispost)\n- [isPut](#isput)\n- [isTrace](#istrace)\n\n**Data types**\n\n- [getFile](#getfile)\n- [hasFile](#hasfile)\n- [getQuery](#getquery)\n- [hasQuery](#hasquery)\n- [getPost](#getpost)\n- [hasPost](#haspost)\n- [getServer](#getserver)\n- [hasServer](#hasserver)\n- [getCookie](#getcookie)\n- [hasCookie](#hascookie)\n- [getHeader](#getheader)\n- [hasHeader](#hasheader)\n- [getBody](#getbody)\n- [hasBody](#hasbody)\n\n**Specific values**\n\n- [getUserAgent](#getuseragent)\n- [getReferer](#getreferer)\n- [getIp](#getip)\n- [isCli](#iscli)\n- [isJson](#isjson)\n- [wantsJson](#wantsjson)\n- [isHttps](#ishttps)\n- [getRequest](#getrequest)\n- [getUrl](#geturl)\n\n\u003chr /\u003e\n\n### validateMethod\n\n**Description:**\n\nReturns valid request method with a fallback to `GET`.\n\nValid request methods include:\n\n- `CONNECT`\n- `DELETE`\n- `GET`\n- `HEAD`\n- `OPTIONS`\n- `PATCH`\n- `POST`\n- `PUT`\n- `TRACE`\n\n**Parameters:**\n\n- `$method` (string)\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::validateMethod('GET');\n```\n\n\u003chr /\u003e\n\n### getMethod\n\n**Description:**\n\nReturns current request method.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::getMethod();\n```\n\n\u003chr /\u003e\n\n### isConnect\n\n**Description:**\n\nIs current request method `CONNECT`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isConnect()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isDelete\n\n**Description:**\n\nIs current request method `DELETE`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isDelete()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isGet\n\n**Description:**\n\nIs current request method `GET`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isGet()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isHead\n\n**Description:**\n\nIs current request method `HEAD`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isHead()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isOptions\n\n**Description:**\n\nIs current request method `OPTIONS`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isOptions()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isPatch\n\n**Description:**\n\nIs current request method `PATCH`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isPatch()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isPost\n\n**Description:**\n\nIs current request method `POST`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isPost()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isPut\n\n**Description:**\n\nIs current request method `PUT`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isPut()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isTrace\n\n**Description:**\n\nIs current request method `TRACE`.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isTrace()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getFile\n\n**Description:**\n\nReturns value of single `$_FILES` array key in dot notation or entire array, with optional default value.\n\n**Parameters:**\n\n- `$key = NULL` (string|null)\n- `$default = NULL` (mixed): Default value to return if array key is not found\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getFile('profile_photo'));\n```\n\n\u003chr /\u003e\n\n### hasFile\n\n**Description:**\n\nChecks if `$_FILES` array key exists in dot notation.\n\n**Parameters:**\n\n- `$key` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasFile('profile_photo')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getQuery\n\n**Description:**\n\nReturns value of single `$_GET` array key in dot notation or entire array, with optional default value.\n\n**Parameters:**\n\n- `$key = NULL` (string|null)\n- `$default = NULL` (mixed): Default value to return if array key is not found\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getQuery());\n```\n\n\u003chr /\u003e\n\n### hasQuery\n\n**Description:**\n\nChecks if `$_GET` array key exists in dot notation.\n\n**Parameters:**\n\n- `$key` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasQuery('page')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getPost\n\n**Description:**\n\nReturns value of single `$_POST` array key in dot notation or entire array, with optional default value.\n\n**Parameters:**\n\n- `$key = NULL` (string|null)\n- `$default = NULL` (mixed): Default value to return if array key is not found\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getPost());\n```\n\n\u003chr /\u003e\n\n### hasPost\n\n**Description:**\n\nChecks if `$_POST` array key exists in dot notation.\n\n**Parameters:**\n\n- `$key` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasPost('username')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getServer\n\n**Description:**\n\nReturns value of single `$_SERVER` array key in dot notation or entire array, with optional default value.\n\n**Parameters:**\n\n- `$key = NULL` (string|null)\n- `$default = NULL` (mixed): Default value to return if array key is not found\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getServer());\n```\n\n\u003chr /\u003e\n\n### hasServer\n\n**Description:**\n\nChecks if `$_SERVER` array key exists in dot notation.\n\n**Parameters:**\n\n- `$key` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasServer('SERVER_NAME')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getCookie\n\n**Description:**\n\nReturns value of single `$_COOKIE` array key in dot notation or entire array, with optional default value.\n\n**Parameters:**\n\n- `$key = NULL` (string|null)\n- `$default = NULL` (mixed): Default value to return if array key is not found\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getCookie());\n```\n\n\u003chr /\u003e\n\n### hasCookie\n\n**Description:**\n\nChecks if `$_COOKIE` array key exists in dot notation.\n\n**Parameters:**\n\n- `$key` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasCookie('cart_id')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getHeader\n\n**Description:**\n\nReturns value of single header array key in dot notation or entire array, with optional default value.\n\n**Parameters:**\n\n- `$key = NULL` (string|null)\n- `$default = NULL` (mixed): Default value to return if array key is not found\n\n**Returns:**\n\n- (mixed)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getHeader());\n```\n\n\u003chr /\u003e\n\n### hasHeader\n\n**Description:**\n\nChecks if header array key exists in dot notation.\n\n**Parameters:**\n\n- `$key` (string)\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasHeader('Content-Type')) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getBody\n\n**Description:**\n\nReturns content body of a request.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nprint_r(Request::getBody());\n```\n\n\u003chr /\u003e\n\n### hasBody\n\n**Description:**\n\nChecks if content body of a request exists.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::hasBody()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getUserAgent\n\n**Description:**\n\nReturns client's user agent.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (mixed): string|null\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::getUserAgent();\n```\n\n\u003chr /\u003e\n\n### getReferer\n\n**Description:**\n\nReturns client's referring URL.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (mixed): string|null\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::getReferer();\n```\n\n\u003chr /\u003e\n\n### getIp\n\n**Description:**\n\nReturns the most probable IP of client with optional default value.\n\n**Parameters:**\n\n- `$default = ''` (string): Default IP address to return if none detected\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::getIp();\n```\n\n\u003chr /\u003e\n\n### isCli\n\n**Description:**\n\nIs the request originating from the command line.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isCli()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isJson\n\n**Description:**\n\nIs the `Content-Type` header for this request JSON.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isJson()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### wantsJson\n\n**Description:**\n\nDoes the `Accept` header for this request expect JSON.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::wantsJson()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### isHttps\n\n**Description:**\n\nIs connection HTTPS.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (bool)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\nif (Request::isHttps()) {\n    // Do something\n}\n```\n\n\u003chr /\u003e\n\n### getRequest\n\n**Description:**\n\nReturns array containing details of the client's request, or string of a specific part of the request.\n\n**Parameters:**\n\n- `$part = ''` (string): Which part of the request to return. Leaving this blank will return the entire array.\n\nValid `$part` values include any of the `PART_*` constants:\n\n- `Requst::PART_METHOD`\n- `Request::PART_PROTOCOL`\n- `Request::PART_HOST`\n- `Request::PART_PATH`\n- `Request::PART_QUERY`\n- `Request::PART_QUERY_STRING`\n- `Request::PART_URL`\n- `Request::PART_FULL_URL`\n\n**Returns:**\n\n- (mixed): array|string\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::getRequest(Request::PART_URL);\n```\n\n\u003chr /\u003e\n\n### getUrl\n\n**Description:**\n\nReturns current URL.\n\n**Parameters:**\n\n- `$include_query = false` (bool): Include the query string, if existing\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\nuse Bayfront\\HttpRequest\\Request;\n\necho Request::getUrl();\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-http-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbayfrontmedia%2Fphp-http-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-http-request/lists"}