This is a proof of concept to get you started. See this comment to ensure you address app security when using in production.
This script can be used standalone, with no other external libraries. The purpose is to send the user to the Steam login page, allow them to login, and handle the response back from Steam to gather their Community ID which can then be used in your application.
In order to use this class, please ensure it is being loaded into your script/framework. For example include 'SteamLogin.php'
;
If needed, add a namespace to the file, example: <?php namespace Acme\Steam;
.
The class has two static methods; genUrl
and validate
.
This method creates a URL which points to Steam, esentially mimicing an OpenId request which the Steam API is able to handle. For more information on this, visit https://steamcommunity.com/dev
The method accepts two parameters;
- A URL which Steam will return to once the user has logged in. If no URL is provided, the script defaults to the current URL path.
- A boolen value of whether the
&
symbol should be converted to&
in the URL created. This is true by default.
Usage:
Default URL: SteamLogin::genUrl();
Specific Return Location: SteamLogin::genUrl('http://mywebsite.com/login/response');
The response of this would sit inside of an anchor tag. Very basic example:
<?php
$url = SteamLogin::genUrl('http://mywebsite.com/login/response');
?>
<a href="<?php echo $url; ?>">Login with Steam</a>
This method parses the URL GET parameters which were passed back from Steam, thus it should sit wherever the returnTo
location of your generated URL pointed to.
The return value of this method is either empty
(string(0) '') or the logged in users Steam Community Id. If the response is empty, we can assume the login URL they tried to access has expired.
$response = SteamLogin::validate();
if( empty( $response ) ) {
return 'The Steam Login request has now expired, please try again.';
}
else {
return $response; // Community ID
}
I'd reccommend using Steam Condenser to query the Steam servers to get more information about your logged in user. The library can be located at https://github.com/koraktor/steam-condenser
not working