Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * get_steam_button
- * Returns a "Sign in through steam" button that will take you to the steam website to login, and then load the callback page.
- * Note that although it says openid in a lot of places, it's not following the openid spec and won't work with most if not all openid libraries
- * This assumes that you have a page at /steam_openid to take the callback
- */
- function get_steam_button() {
- return '<a id="openid_link" href="https://steamcommunity.com/openid/login?openid.ns=http://specs.openid.net/auth/2.0&openid.mode=checkid_setup&openid.return_to=' . $base_url . $base_path . 'steam_openid/;&openid.realm=' . $base_url . '&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select">
- <img src="http://steamcommunity.com/public/images/signinthroughsteam/sits_small.png" />
- </a>',
- );
- }
- }
- /*
- * steam_openid
- * This is an example callback for the steam_openid page
- */
- function steam_openid() {
- if(!isset($_GET['openid_assoc_handle']))
- return "Error attempting to validate your steam account, please try again.";
- $params = array(
- 'openid.assoc_handle' => $_GET['openid_assoc_handle'],
- 'openid.signed' => $_GET['openid_signed'],
- 'openid.sig' => $_GET['openid_sig'],
- 'openid.ns' => 'http://specs.openid.net/auth/2.0',
- );
- $signed = explode(',', $_GET['openid_signed']);
- foreach($signed as $item)
- {
- $val = $_GET['openid_' . str_replace('.', '_', $item)];
- $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
- }
- $params['openid.mode'] = 'check_authentication';
- $data = http_build_query($params);
- $context = stream_context_create(array(
- 'http' => array(
- 'method' => 'POST',
- 'header' =>
- "Accept-language: en\r\n".
- "Content-type: application/x-www-form-urlencoded\r\n" .
- "Content-Length: " . strlen($data) . "\r\n",
- 'content' => $data,
- ),
- ));
- $result = file_get_contents("https://steamcommunity.com/openid/login", false, $context);
- preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
- $steamid64 = is_numeric($matches[1]) ? $matches[1] : 0;
- if (preg_match("#is_valid\s*:\s*true#i", $result) != 1) {
- global $base_url;
- global $base_path;
- header("Location: https://steamcommunity.com/openid/login?openid.ns=http://specs.openid.net/auth/2.0&openid.mode=checkid_setup&openid.return_to=' . $base_url . $base_path . 'steam_openid/&openid.realm=' . $base_url . '&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select");
- return "Error attempting to validate your steam account, please try again.";
- }
- // If you make it past the above link, you've got a validated steam account. $steamid64 is like a $user->id for steam accounts, so it's the main thing you'll want to store.
- return "You have successfully linked your steam account.";
- }
- /*
- * Load steam XML
- * Call this function with the steamid64 obtained from steam_openid to load the XML feed for that user. This contains name, avatar, and lots of other information
- */
- function steam_load_xml($steamid64) {
- $url = "http://steamcommunity.com/profiles/" . $steamid64 . "/?xml=1";
- $context = stream_context_create(array('http' => array('timeout' => 5)));
- if($fp = @fopen($url, 'r', FALSE, $context))
- {
- $xml = stream_get_contents($fp);
- fclose($fp);
- $xml = new SimpleXMLElement($xml);
- return $xml;
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement