{"id":23071859,"url":"https://github.com/chipslays/php-url-fingerprint","last_synced_at":"2026-02-09T07:31:16.270Z","repository":{"id":267600438,"uuid":"901769047","full_name":"chipslays/php-url-fingerprint","owner":"chipslays","description":"🔗 Pathor is a PHP library for normalizing, analyzing, and comparing URLs.","archived":false,"fork":false,"pushed_at":"2024-12-12T10:07:15.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-02T01:28:35.626Z","etag":null,"topics":["fingerprint","url","url-fingerprint","url-normalization","url-normalizer"],"latest_commit_sha":null,"homepage":"https://github.com/chipslays/php-url-fingerprint","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/chipslays.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-11T09:28:22.000Z","updated_at":"2024-12-12T10:07:18.000Z","dependencies_parsed_at":"2025-04-30T07:09:23.856Z","dependency_job_id":"6a599b25-55ec-49bf-8f58-3651403a7bd0","html_url":"https://github.com/chipslays/php-url-fingerprint","commit_stats":null,"previous_names":["chipslays/php-url-fingerprint"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chipslays/php-url-fingerprint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphp-url-fingerprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphp-url-fingerprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphp-url-fingerprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphp-url-fingerprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chipslays","download_url":"https://codeload.github.com/chipslays/php-url-fingerprint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fphp-url-fingerprint/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29258737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T04:11:57.159Z","status":"ssl_error","status_checked_at":"2026-02-09T04:11:56.117Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["fingerprint","url","url-fingerprint","url-normalization","url-normalizer"],"created_at":"2024-12-16T07:17:17.396Z","updated_at":"2026-02-09T07:31:16.254Z","avatar_url":"https://github.com/chipslays.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔗 Pathor\n\n## Overview\n\nPathor is a PHP library for normalizing, analyzing, and comparing URLs. It is built on top of the [League\\Uri](https://uri.thephpleague.com/) library and offers an easy-to-use API for common URL-related operations.\n\n## Installation\n\nInstall the library via Composer:\n\n```bash\ncomposer require pathor/url\n```\n\n## Features\n\n- Normalize URLs by standardizing components (scheme, host, path, query, etc.).\n- Generate a consistent fingerprint (hash) for URLs.\n- Compare multiple URLs to check if they are equivalent.\n- Parse URLs into their individual components.\n- Assemble URLs from their components.\n- Customize normalization with handlers and configurations.\n\n## Usage\n\n### Basic Usage\n\nHere is a quick example of how to use the Pathor library:\n\n```php\nuse Pathor\\Url;\n\n$pathor = new Url;\n\n$url = 'https://www.example.com/path///../a/b/../c//ё//hello world/?ref=google\u0026b=2\u0026a=1\u0026\u0026=\u0026\u0026foo[1]=222\u0026foo[0]=111#hello world';\n\n// Normalize URL\n$normalizedUrl = $pathor-\u003enormalize($url);\ndd($normalizedUrl); // https://www.example.com/path/a/c/%D1%91/hello%20world?a=1\u0026b=2\u0026foo%5B%5D=111\u0026foo%5B%5D=222#hello%20world\n\n// Generate fingerprint\n$fingerprint = $pathor-\u003efingerprint($url);\ndd($fingerprint); // b18e86f5d2da88269fd0895af1178d8305ae78fe3fa3e61195af6b50a60f333d\n\n// Compare URLs\n$isEqual = $pathor-\u003eequals(\n    'https://www.example.com/path/a/c/%D1%91/hello%20world?a=1\u0026b=2\u0026foo%5B%5D=111\u0026foo%5B%5D=222#hello%20world',\n    'https://www.example.com/path///../a/b/../c//ё//hello world/?ref=google\u0026b=2\u0026a=1\u0026\u0026=\u0026\u0026foo[1]=222\u0026foo[0]=111#hello world',\n    'https://www.example.com/path//a/b/../c//ё//hello world/?ref=google\u0026b=2\u0026a=1\u0026\u0026=\u0026\u0026\u0026foo[]=111\u0026foo[]=222#hello world',\n);\ndd($isEqual); // Outputs: bool(true)\n\n// Get URL details\n$details = $pathor-\u003edetails($url);\ndd($details); // Outputs an array with parsed and normalized components\n```\n\n### Examples\n\nExamples can be found [here](./examples).\n\n### Configuration\n\nThe `Url` class can be customized with configuration options to adjust the normalization behavior. These options include:\n\n- **`fingerprint`**: Set the hashing algorithm for URL fingerprints (default: `sha256`).\n- **`query`**: Customize query string handling.\n  - `withoutDuplicates`: Remove duplicate query parameters.\n  - `withoutEmptyPairs`: Remove empty query parameters.\n  - `withSortedParams`: Sort query parameters alphabetically.\n  - `withoutTrackingParams`: Remove known tracking parameters (e.g., `utm_source`).\n- **`path`**: Customize path normalization.\n  - `withoutDotSegments`: Remove `.` and `..` segments in the path.\n  - `withoutEmptySegments`: Remove empty segments from the path.\n  - `withoutTrailingSlash`: Remove trailing slashes.\n\n#### Default Configuration\n\n```php\n$config = [\n    'fingerprint' =\u003e 'sha256', // https://www.php.net/manual/en/function.hash-algos.php\n\n    'query' =\u003e [\n        'withoutDuplicates' =\u003e true,\n        'withoutEmptyPairs' =\u003e true,\n        'withoutNumericIndices' =\u003e true,\n        'withSortedParams' =\u003e true,\n        'withoutTrackingParams' =\u003e true,\n        'trackingParamsList' =\u003e static::QUERY_TRACKING_PARAMS,\n    ],\n\n    'path' =\u003e [\n        'withoutDotSegments' =\u003e true,\n        'withoutEmptySegments' =\u003e true,\n        'withoutTrailingSlash' =\u003e true,\n    ],\n];\n\n$pathor = new Url($config);\n```\n\n### Handlers (Custom normalization)\n\nCustom handlers allow you to define specific rules for processing URL components. Handlers are functions that take the original and normalized values as parameters.\n\nExample:\n\n```php\n$handlers = [\n    'scheme' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e $normalized,\n    'user' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e $normalized,\n    'password' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e $normalized,\n    'host' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e strtoupper($original),\n    'port' =\u003e fn(?int $normalized, ?int $original): ?int =\u003e $normalized,\n    'path' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e $normalized,\n    'query' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e $normalized,\n    'fragment' =\u003e fn(?string $normalized, ?string $original): ?string =\u003e $normalized,\n];\n\n$pathor = new Url(handlers: $handlers);\n```\n\n### Documentation\n\n#### `normalize(string $url): string`\n\nNormalizes a given URL by standardizing its components. By default, this includes:\n- Lowercasing the scheme and host.\n- Remove duplicate query parameters.\n- Remove empty query parameters.\n- Sort query parameters alphabetically.\n- Remove known tracking parameters (e.g., `utm_source`).\n- Remove `.` and `..` segments in the path.\n- Remove empty segments from the path.\n- Remove trailing slashes.\n- And more.\n\nExample:\n\n```php\n$normalized = $pathor-\u003enormalize('HTTP://Example.COM/../a/B/./');\necho $normalized; // Outputs: http://example.com/a/B\n\n$normalized = $pathor-\u003enormalize('https://сайт.рф');\necho $normalized; // Outputs: https://xn--80aswg.xn--p1ai\n```\n\n#### `fingerprint(string $url): string`\n\nGenerates a hash based on the normalized URL. The hashing algorithm can be configured.\n\nExample:\n\n```php\n$fingerprint = $pathor-\u003efingerprint('https://example.com/path?param=value');\n\necho $fingerprint; // Outputs a hash string (e.g., SHA256)\n```\n\n#### `equals(string ...$urls): bool`\n\nCompares two or more URLs to check if they are equivalent after normalization. Throws an exception if less than two URLs are provided.\n\nExample:\n\n```php\n$areEqual = $pathor-\u003eequals(\n    'https://example.com/?utm_source=google',\n    'https://example.com:443?ref=site\u0026=',\n    'https://example.com:443/',\n    'https://example.com:443/?#',\n    'https://example.com:443'\n);\nvar_dump($areEqual); // Outputs: bool(true)\n```\n\n#### `parse(string $url): array`\n\nBreaks a URL into its components, returning an associative array.\n\nExample:\n\n```php\n$components = $pathor-\u003eparse('https://user:pass@example.com:8080/path?query=value#fragment');\n\ndd($components);\n\n// ^ array:8 [\n//   \"scheme\" =\u003e \"https\"\n//   \"host\" =\u003e \"example.com\"\n//   \"user\" =\u003e \"user\"\n//   \"password\" =\u003e \"pass\"\n//   \"port\" =\u003e 8080\n//   \"path\" =\u003e \"/path\"\n//   \"query\" =\u003e \"query=value\"\n//   \"fragment\" =\u003e \"fragment\"\n// ]\n```\n\n#### `build(array $components): string`\n\nAssembles a URL from its components. Accepts an associative array with keys like `scheme`, `host`, `path`, etc.\n\nExample:\n\n```php\n$url = $pathor-\u003ebuild([\n    'scheme' =\u003e 'https',\n    'host' =\u003e 'example.com',\n    'path' =\u003e 'new-path',\n    'query' =\u003e ['param' =\u003e 'value'], // or string (http_build_query)\n    'fragment' =\u003e 'section'\n]);\n\necho $url; // Outputs: https://example.com/new-path?param=value#section\n```\n\n#### `details(string $url): array`\n\nReturns a detailed breakdown of a normalized URL, including original and modified components.\n\nExample:\n\n```php\n$details = $pathor-\u003edetails('https://www.example.com:443/path///../a/b/../c//ё//hello world/?ref=google\u0026b=2\u0026a=1\u0026\u0026=\u0026\u0026foo[1]=222\u0026foo[0]=111#hello world');\n\ndd($details);\n\n// ^ array:4 [\n//   \"fingerprint\" =\u003e \"4c64095f06900806842e22f93ee151ab\"\n//   \"original_url\" =\u003e \"https://www.example.com:443/path///../a/b/../c//ё//hello world/?ref=google\u0026b=2\u0026a=1\u0026\u0026=\u0026\u0026foo[1]=222\u0026foo[0]=111#hello world\"\n//   \"normalized_url\" =\u003e \"https://www.example.com/path/a/c/%D1%91/hello%20world?a=1\u0026b=2\u0026foo%5B%5D=111\u0026foo%5B%5D=222#hello%20world\"\n//   \"parsed_url\" =\u003e array:8 [\n//     \"scheme\" =\u003e \"https\"\n//     \"host\" =\u003e \"www.example.com\"\n//     \"user\" =\u003e null\n//     \"password\" =\u003e null\n//     \"port\" =\u003e null\n//     \"path\" =\u003e \"/path/a/c/%D1%91/hello%20world\"\n//     \"query\" =\u003e \"a=1\u0026b=2\u0026foo%5B%5D=111\u0026foo%5B%5D=222\"\n//     \"fragment\" =\u003e \"hello%20world\"\n//   ]\n// ]\n```\n\n## Contributing\n\nContributions are welcome! Please submit pull requests or open issues.\n\n## License\n\nThis library is licensed under the MIT License. See the [LICENSE](./license) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fphp-url-fingerprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchipslays%2Fphp-url-fingerprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fphp-url-fingerprint/lists"}