{"id":15409477,"url":"https://github.com/xpaw/steamid.php","last_synced_at":"2025-04-08T01:35:24.540Z","repository":{"id":27983415,"uuid":"31477159","full_name":"xPaw/SteamID.php","owner":"xPaw","description":"🆔 PHP library to work with SteamIDs","archived":false,"fork":false,"pushed_at":"2025-03-31T18:28:27.000Z","size":113,"stargazers_count":155,"open_issues_count":0,"forks_count":19,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-01T00:33:54.676Z","etag":null,"topics":["hacktoberfest","php","steam","steamid","valve"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/xpaw/steamid","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/xPaw.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}},"created_at":"2015-02-28T21:17:45.000Z","updated_at":"2025-03-31T18:28:31.000Z","dependencies_parsed_at":"2023-01-14T07:52:21.006Z","dependency_job_id":"9fe0e0cd-3e2b-4942-ad10-876bec582fbd","html_url":"https://github.com/xPaw/SteamID.php","commit_stats":{"total_commits":146,"total_committers":7,"mean_commits":"20.857142857142858","dds":"0.40410958904109584","last_synced_commit":"d2c86d64750595e1dfb4b17048b6d91fcd1d4e78"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xPaw%2FSteamID.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xPaw%2FSteamID.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xPaw%2FSteamID.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xPaw%2FSteamID.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xPaw","download_url":"https://codeload.github.com/xPaw/SteamID.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247761050,"owners_count":20991531,"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":["hacktoberfest","php","steam","steamid","valve"],"created_at":"2024-10-01T16:40:10.710Z","updated_at":"2025-04-08T01:35:24.498Z","avatar_url":"https://github.com/xPaw.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SteamID.php [![Packagist](https://img.shields.io/packagist/dt/xpaw/steamid.svg)](https://packagist.org/packages/xpaw/steamid) [![Codecov](https://codecov.io/gh/xPaw/SteamID.php/graph/badge.svg?token=MykhdiNWe2)](https://codecov.io/gh/xPaw/SteamID.php)\n\nThis 64bit structure is used for identifying various objects on the Steam \nnetwork. This library provides an easy way to work with SteamIDs and makes \nconversions easy.\n\nThis library does not use subtraction hacks like described on \n[Valve Developer Wiki](https://developer.valvesoftware.com/wiki/SteamID), \nor used in many other functions.\n\nSteamID.php requires modern PHP version, and [GMP module](http://php.net/manual/en/book.gmp.php)\nto be installed to perform operations 64-bit math.\n\n## Brief overview\n\nA SteamID is made up of four parts: its **universe**, its **type**, its \n**instance**, and its **account ID**.\n\n- **Universe**: Currently there are 5 universes. A universe is a unique \n  instance of Steam. You'll probably only be interacting with the public universe, \n  which is the regular Steam. Only Valve employees can access non-public universes.\n- **Type**: A SteamID's type determines what it identifies. The most common type \n  is *individual*, for user accounts. There are also other types such as *clans* \n  (Steam groups), *gameservers*, and more.\n- **Instance**: Steam allows three simultaneous user account instances right now \n  *(1 = desktop, 2 = console, 4 = web, 0 = all)*\n- **Account ID**: This represents a unique account of a type.\n\n## Using this library\n\nIt's really easy to use it, as constructor automatically figures out given input \nand works its magic from there. If provided SteamID is not in a valid format, an \n`InvalidArgumentException` is thrown. You can call `IsValid` on given SteamID \ninstance to perform various checks which make sure that given account type / \nuniverse / instance are correct. You can view [test file](.test.php) for \nmultiple examples on how to manipulate SteamIDs.\n\n### Example\n\n```php\nuse xPaw\\Steam\\SteamID;\n\ntry\n{\n\t// Constructor also accepts Steam3 and Steam2 representations\n\t$s = new SteamID( '76561197984981409' );\n}\ncatch( InvalidArgumentException $e )\n{\n\techo 'Given SteamID could not be parsed.';\n}\n\n// Renders SteamID in it's Steam3 representation (e.g. [U:1:24715681])\necho $s-\u003eRenderSteam3() . PHP_EOL;\n\n// Renders SteamID in it's Steam2 representation (e.g. STEAM_0:1:12357840)\necho $s-\u003eRenderSteam2() . PHP_EOL;\n\n// Converts this SteamID into it's 64bit integer form (e.g. 76561197984981409)\necho $s-\u003eConvertToUInt64() . PHP_EOL;\n```\n\nAlso see [`VanityURLs.php`](/VanityURLs.php) for parsing any user input including URLs.\nIf you're going to process user input, `SteamID::SetFromURL()` is all you need to use.\n\n### SteamID normalization\n\nIf you run some website where users can enter their own SteamIDs, sometimes you\nmight encounter SteamIDs which have wrong universe or instanceid set, which \nwill result in a completely different, yet valid, SteamID. To avoid this, you\ncan manipulate given SteamID and set universe to public and instance to \ndesktop.\n\n```php\nuse xPaw\\Steam\\SteamID;\n\ntry\n{\n\t$s = new SteamID( $ID );\n\t\n\tif( $s-\u003eGetAccountType() !== SteamID::TypeIndividual )\n\t{\n\t\tthrow new InvalidArgumentException( 'We only support individual SteamIDs.' );\n\t}\n\telse if( !$s-\u003eIsValid() )\n\t{\n\t\tthrow new InvalidArgumentException( 'Invalid SteamID.' );\n\t}\n\t\n\t$s-\u003eSetAccountInstance( SteamID::DesktopInstance );\n\t$s-\u003eSetAccountUniverse( SteamID::UniversePublic );\n\n\tvar_dump( $s-\u003eRenderSteam3() ); // [U:1:24715681]\n\tvar_dump( $s-\u003eConvertToUInt64() ); // 76561197984981409\n}\ncatch( InvalidArgumentException $e )\n{\n\techo $e-\u003egetMessage();\n}\n```\n\nAfter doing these steps, you can call `RenderSteam3`, `RenderSteam2` or \n`ConvertToUInt64` to get normalized SteamID.\n\nSee [`Example.php`](/Example.php) for a fully fledged example.\n\n## Functions\n\n\u003ctable\u003e\n\t\u003cthead\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003cth\u003eName\u003c/th\u003e\n\t\t\t\u003cth\u003eParameters\u003c/th\u003e\n\t\t\t\u003cth\u003eDescription\u003c/th\u003e\n\t\t\u003c/tr\u003e\n\t\u003c/thead\u003e\n\t\u003ctbody\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eIsValid\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eGets a value indicating whether this instance is valid.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eRenderSteam2\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eRenders this instance into it's Steam2 \"STEAM_\" representation.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eRenderSteam3\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eRenders this instance into it's Steam3 representation.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eRenderSteamInvite\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eEncodes accountid as HEX which can be used in `http://s.team/p/` URL.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eRenderCsgoFriendCode\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eEncodes accountid as CS:GO friend code.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eConvertToUInt64\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eConverts this SteamID into it's 64bit integer form.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetFromURL\u003c/td\u003e\n\t\t\t\u003ctd\u003estring, callback\u003c/td\u003e\n\t\t\t\u003ctd\u003eParse any user input including URLs and just steam ids.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetFromUInt64\u003c/td\u003e\n\t\t\t\u003ctd\u003estring or int (e.g 765...)\u003c/td\u003e\n\t\t\t\u003ctd\u003eSets the various components of this SteamID from a 64bit integer form.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetFromCsgoFriendCode\u003c/td\u003e\n\t\t\t\u003ctd\u003estring\u003c/td\u003e\n\t\t\t\u003ctd\u003eSets the accountid of this SteamID from a CS:GO friend code. Resets other components to default values.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eGetAccountID\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eGets the account id.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eGetAccountInstance\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eGets the account instance.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eGetAccountType\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eGets the account type.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eGetAccountUniverse\u003c/td\u003e\n\t\t\t\u003ctd\u003e-\u003c/td\u003e\n\t\t\t\u003ctd\u003eGets the account universe.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetAccountID\u003c/td\u003e\n\t\t\t\u003ctd\u003eNew account id\u003c/td\u003e\n\t\t\t\u003ctd\u003eSets the account id.\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetAccountInstance\u003c/td\u003e\n\t\t\t\u003ctd\u003eNew account instance\u003c/td\u003e\n\t\t\t\u003ctd\u003eSets the account instance. (e.g. \u003ccode\u003eSteamID::DesktopInstance\u003c/code\u003e)\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetAccountType\u003c/td\u003e\n\t\t\t\u003ctd\u003eNew account type\u003c/td\u003e\n\t\t\t\u003ctd\u003eSets the account type. (e.g. \u003ccode\u003eSteamID::TypeAnonGameServer\u003c/code\u003e)\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003eSetAccountUniverse\u003c/td\u003e\n\t\t\t\u003ctd\u003eNew account universe\u003c/td\u003e\n\t\t\t\u003ctd\u003eSets the account universe. (e.g. \u003ccode\u003eSteamID::UniversePublic\u003c/code\u003e)\u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\u003c/tbody\u003e\n\u003c/table\u003e\n\n## New Steam invite URLs\n\nValve introduce a new way of sharing profile URLs (https://s.team/p/hjqp or https://steamcommunity.com/user/hjqp). The encoding is simply hex encoded account id and each letter being replaced with a custom alphabet. While HEX originally is `0-9a-f`, in the converted version numbers and letters `a` or `e` are not included, but they still work in the URL because Valve does a single pass replacement.\n\nThis library natively supports parsing `s.team/p/` or `steamcommunity.com/user/` URLs in `SetFromURL` function.\n\nHere's the mapping of replacements:\n\nHex | Letter\n--|--\n0 | b\n1 | c\n2 | d\n3 | f\n4 | g\n5 | h\n6 | j\n7 | k\n8 | m\n9 | n\na | p\nb | q\nc | r\nd | t\ne | v\nf | w\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpaw%2Fsteamid.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxpaw%2Fsteamid.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpaw%2Fsteamid.php/lists"}