SHARE
TWEET

Example Steam OAuth with LightOpenID

JTX Jun 30th, 2012 6,524 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <?php
  3. # Logging in with Steam accounts requires setting special identity, so this example shows how to do it.
  4. # http://steamcommunity.com/dev/
  5. require 'openid.php';
  6. try {
  7.     # Change 'localhost' to your domain name.
  8.    $openid = new LightOpenID('localhost');
  9.     if(!$openid->mode) {
  10.         if(isset($_GET['login'])) {
  11.             $openid->identity = 'http://steamcommunity.com/openid';
  12.             header('Location: ' . $openid->authUrl());
  13.         }
  14. ?>
  15. <form action="?login" method="post">
  16.     <input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png">
  17. </form>
  18. <?php
  19.     } elseif($openid->mode == 'cancel') {
  20.         echo 'User has canceled authentication!';
  21.     } else {
  22.         if($openid->validate()) {
  23.                 $id = $openid->identity;
  24.                 // identity is something like: http://steamcommunity.com/openid/id/76561197994761333
  25.                 // we only care about the unique account ID at the end of the URL.
  26.                 $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
  27.                 preg_match($ptn, $id, $matches);
  28.                 echo "User is logged in (steamID: $matches[1])\n";
  29.         } else {
  30.                 echo "User is not logged in.\n";
  31.         }
  32.  
  33.     }
  34. } catch(ErrorException $e) {
  35.     echo $e->getMessage();
  36. }
  37. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top