• Stars
    star
    142
  • Rank 257,362 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🆔 PHP library to work with SteamIDs

SteamID.php Packagist

This 64bit structure is used for identifying various objects on the Steam network. This library provides an easy way to work with SteamIDs and makes conversions easy.

This library does not use subtraction hacks like described on Valve Developer Wiki, or used in many other functions.

SteamID.php requires modern PHP version, and GMP module to be installed to perform operations 64-bit math.

Brief overview

A SteamID is made up of four parts: its universe, its type, its instance, and its account ID.

  • Universe: Currently there are 5 universes. A universe is a unique instance of Steam. You'll probably only be interacting with the public universe, which is the regular Steam. Only Valve employees can access non-public universes.
  • Type: A SteamID's type determines what it identifies. The most common type is individual, for user accounts. There are also other types such as clans (Steam groups), gameservers, and more.
  • Instance: Steam allows three simultaneous user account instances right now (1 = desktop, 2 = console, 4 = web, 0 = all)
  • Account ID: This represents a unique account of a type.

Using this library

It's really easy to use it, as constructor automatically figures out given input and works its magic from there. If provided SteamID is not in a valid format, an InvalidArgumentException is thrown. You can call IsValid on given SteamID instance to perform various checks which make sure that given account type / universe / instance are correct. You can view test file for multiple examples on how to manipulate SteamIDs.

Example

try
{
	// Constructor also accepts Steam3 and Steam2 representations
	$s = new SteamID( '76561197984981409' );
}
catch( InvalidArgumentException $e )
{
	echo 'Given SteamID could not be parsed.';
}

// Renders SteamID in it's Steam3 representation (e.g. [U:1:24715681])
echo $s->RenderSteam3() . PHP_EOL;

// Renders SteamID in it's Steam2 representation (e.g. STEAM_0:1:12357840)
echo $s->RenderSteam2() . PHP_EOL;

// Converts this SteamID into it's 64bit integer form (e.g. 76561197984981409)
echo $s->ConvertToUInt64() . PHP_EOL;

Also see VanityURLs.php for parsing any user input including URLs. If you're going to process user input, SteamID::SetFromURL() is all you need to use.

SteamID normalization

If you run some website where users can enter their own SteamIDs, sometimes you might encounter SteamIDs which have wrong universe or instanceid set, which will result in a completely different, yet valid, SteamID. To avoid this, you can manipulate given SteamID and set universe to public and instance to desktop.

try
{
	$s = new SteamID( $ID );
	
	if( $s->GetAccountType() !== SteamID::TypeIndividual )
	{
		throw new InvalidArgumentException( 'We only support individual SteamIDs.' );
	}
	else if( !$s->IsValid() )
	{
		throw new InvalidArgumentException( 'Invalid SteamID.' );
	}
	
	$s->SetAccountInstance( SteamID::DesktopInstance );
	$s->SetAccountUniverse( SteamID::UniversePublic );

	var_dump( $s->RenderSteam3() ); // [U:1:24715681]
	var_dump( $s->ConvertToUInt64() ); // 76561197984981409
}
catch( InvalidArgumentException $e )
{
	echo $e->getMessage();
}

After doing these steps, you can call RenderSteam3, RenderSteam2 or ConvertToUInt64 to get normalized SteamID.

See Example.php for a fully fledged example.

Functions

Name Parameters Description
IsValid - Gets a value indicating whether this instance is valid.
RenderSteam2 - Renders this instance into it's Steam2 "STEAM_" representation.
RenderSteam3 - Renders this instance into it's Steam3 representation.
RenderSteamInvite - Encodes accountid as HEX which can be used in `http://s.team/p/` URL.
RenderCsgoFriendCode - Encodes accountid as CS:GO friend code.
ConvertToUInt64 - Converts this SteamID into it's 64bit integer form.
SetFromURL string, callback Parse any user input including URLs and just steam ids.
SetFromUInt64 string or int (e.g 765...) Sets the various components of this SteamID from a 64bit integer form.
SetFromCsgoFriendCode string Sets the accountid of this SteamID from a CS:GO friend code. Resets other components to default values.
GetAccountID - Gets the account id.
GetAccountInstance - Gets the account instance.
GetAccountType - Gets the account type.
GetAccountUniverse - Gets the account universe.
SetAccountID New account id Sets the account id.
SetAccountInstance New account instance Sets the account instance. (e.g. SteamID::DesktopInstance)
SetAccountType New account type Sets the account type. (e.g. SteamID::TypeAnonGameServer)
SetAccountUniverse New account universe Sets the account universe. (e.g. SteamID::UniversePublic)

New Steam invite URLs

Valve 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.

This library natively supports parsing s.team/p/ or steamcommunity.com/user/ URLs in SetFromURL function.

Here's the mapping of replacements:

Hex Letter
0 b
1 c
2 d
3 f
4 g
5 h
6 j
7 k
8 m
9 n
a p
b q
c r
d t
e v
f w

License

MIT

More Repositories

1

PHP-Minecraft-Query

🐘 PHP library to query Minecraft servers
PHP
727
star
2

PHP-Source-Query

🐘 PHP library to query servers that implement Steam query protocol (also known as Source Engine Query protocol)
PHP
577
star
3

CS2

🔫 Counter-Strike 2 stuff
148
star
4

SteamWebAPIDocumentation

📃 An automatically generated list of Steam Web API interfaces, methods and parameters. Allows you to craft requests in the browser.
Vue
138
star
5

SteamWebPipes

🚀 Pushes Steam changelists to WebSocket clients
C#
120
star
6

mcstatus

💡 Minecraft services status checker
PHP
112
star
7

AMXX-Plugins

💌 Most of my AMXX plugins that I've ever written
Pawn
73
star
8

DomainNameSearch

🔥 Lookup domain names against all extensions
HTML
70
star
9

FlatMumble

💬 Flat and unified mumble theme (MUMBLE 1.3.0 SHIPS WITH MODIFIED VERSION OF THIS THEME)
40
star
10

HTTPsys

🔥 A checker site for MS15-034 / CVE-2015-1635
PHP
38
star
11

SteamOpenID.php

🐘 A correct and simple implementation of OpenID authentication for Steam
PHP
37
star
12

Steam-Card-Farmer

🃏 Idle your Steam games to get trading cards
JavaScript
37
star
13

GitHub-WebHook

🐱 Validates and processes GitHub's webhooks
PHP
30
star
14

SteamLicenseParser

📦 Parsers your Steam licenses and generates some stats
HTML
29
star
15

Crimp.php

⚡ A simple multi curl implementation, optimized for high concurrency.
PHP
25
star
16

Re-Crono-HexChat

🕶 A dark GTK theme for HexChat
25
star
17

adventofcode-solutions

🎄 My solutions to https://adventofcode.com/
C#
24
star
18

smtp-forwarder

Simple SMTP message to HTTP forwarder
JavaScript
15
star
19

SteamDepotFileVerifier

Find unknown files in Steam game folders by comparing against depotcache manifests
C#
15
star
20

FreeWarden

🔎 Monitor whois, certificate, and dns changes
PHP
13
star
21

AMXX-Gag

🔇 This plugin allows you to gag players from using say_team, say or voicecomm
SourcePawn
13
star
22

DumpStrings

macho-strings will programmatically read an Mach-O binary's string sections within a given binary. This is meant to be much like the strings UNIX utility, however is purpose built for Mach-O binaries.
Go
11
star
23

EntityLumpDumper

Dump entity lump from BSP maps (CS:GO, TF2, etc..)
C#
9
star
24

WendySharp

👮 Wendy# — A C# IRC bot
C#
8
star
25

MumblePing

🎙 A simple function to execute UDP Ping on Mumble servers
PHP
8
star
26

TwitterToWebhook

🐦 Stream tweets to a webhook url
C#
7
star
27

CompareArrays.php

🍌 Diffing multi dimensional arrays the easy way
PHP
7
star
28

xpaw.me

🐾 My personal website
HTML
6
star
29

znc-prioritysend

⏫ Allows certain messages to be placed in front of the send queue
C++
6
star
30

OpenplanetDriveAlone

👆 A Trackmania 2020 plugin to automatically click "Drive Alone" when loading a map in Solo to avoid selecting a ghost to race against.
AngelScript
6
star
31

urlshortener

🔗 A simple url shortener.
PHP
5
star
32

xPaw

4
star
33

php-vue-template

HTML-based template for PHP syntax inspired by Vue.
PHP
3
star
34

PHP-StarMade-Query

🐘 PHP library to query StarMade servers
PHP
3
star
35

BombGame

💣 A game mode for CS:GO
SourcePawn
3
star
36

steam-tags-game

🎲 This is our defunct mini game
HTML
2
star
37

AMXX-Language-Analyzer

🈂️ Analyze AMXX translation files for missing and erroneous translations
PHP
2
star
38

Bugsnuggle

🐛 A crappy local clone of Bugsnag
PHP
2
star
39

PHP-TUG-Query

🐘 PHP library to query TUG servers
PHP
1
star
40

test-secrets

1
star
41

.github

😾 Default community health files
1
star