0

Well this is my index.php file:

<?php
require 'openid.php';
try {
    $openid = new LightOpenID('localhost');
    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'http://steamcommunity.com/openid';
            header('Location: ' . $openid->authUrl());
        }
?>
<form action="?login" method="post">
    <button>Login with Steam</button>
</form>
<?php
    } elseif($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}

With that it echo's out:

"User http://steamcommunity.com/id/**ID HERE OF USER WHO LOGGED IN**/ has/has not logged in."

So I tried to echo out $openid->identity(); & validate() before the "User ------" but it would just give me:

Fatal error: Call to undefined method LightOpenID::identity() in D:\wamp\www\index.php on line 19

And if I do it after the "User ----------", it will print out "http://steamcommunity.com/id/**/ has/has not logged in". So my question is, how would I only print out the actual ID and not the rest? And could someone explain the -> stuff, I believe it has something to do with OOP, but yer.

prk
  • 3,781
  • 6
  • 17
  • 27

1 Answers1

0

I have answered a similar question here. Which should be able to get your started.

To answer your question about how to get just the ID, that is also done in the code presented in that answer. If the user has been validated, it will pull the unique player ID from the returned value. That returned value looks like http://steamcommunity.com/openid/id/76561197960435530, and you need just the 76561197960435530 part.

This is done via these few lines of code:

$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
echo "User is logged in (steamID: $matches[1])\n";

This sets a regex that will get id from the returned string. You may want to verify what you are receiving back, because it actually returns a string like http://steamcommunity.com/openid/id/. Notice the openid portion of the URL. If you aren't getting that, there is an issue with your openid library.

Community
  • 1
  • 1
Andy
  • 49,085
  • 60
  • 166
  • 233