This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[STEAM API] Simple php steam login in your site


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jankec90
Junior Member
Join Date: Jan 2013
Location: Wonderland
Old 01-25-2013 , 07:13   [STEAM API] Simple php steam login in your site
Reply With Quote #1

It can be used to store.
Players can easily use the data and can also be saved MYSQL database.
This is a very simple example, and can be easily modified.


Api key register: http://steamcommunity.com/dev/apikey
Download Openid: http://gitorious.org/lightopenid/lig...tarball/master

Download this API: https://www.dropbox.com/s/pflzg8wabv...teamWebAPI.rar

PHP Code:
<?php
error_reporting
(E_ERROR E_PARSE E_WARNING);

$user = new user;
$user->apikey "xxxxxxxxxxxxxxxxxxx"// put your API key here
$user->domain "localhost"// put your domain


class user
{
    public static 
$apikey;
    public static 
$domain;

    public function 
GetPlayerSummaries ($steamid)
    {
        
$response file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' $this->apikey '&steamids=' $steamid);
        
$json json_decode($response);
        return 
$json->response->players[0];
    }

    public function 
signIn ()
    {
        require_once 
'openid.php';
        
$openid = new LightOpenID($this->domain);
        if(!
$openid->mode)
        {
            
$openid->identity 'http://steamcommunity.com/openid';
            
header('Location: ' $openid->authUrl());
        }
        elseif(
$openid->mode == 'cancel')
        {
            print (
'User has canceled authentication!');
        }
        else
        {
            if(
$openid->validate())
            {
                
preg_match("/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/"$openid->identity$matches); // steamID: $matches[1]
                
setcookie('steamID'$matches[1], time()+(60*60*24*7), '/'); // 1 week
                
header('Location: /');
                exit;
            }
            else
            {
                print (
'fail');
            }
        }
    }
}

if(isset(
$_GET['login']))
{
    
$user->signIn();
}
if (
array_key_exists'logout'$_POST ))
{
    
setcookie('steamID''', -1'/');
    
header('Location: /');
}


if(!
$_COOKIE['steamID'])
{
    print (
'<form action="?login" method="post">
        <input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png"/>
        </form>'
);
}
else
{
    print(
'<form method="post"><button title="Logout" name="logout">Logout</button></form>');
    echo 
$user->GetPlayerSummaries($_COOKIE['steamID'])->personaname;
}
?>
__________________
sorry for the bad english

Last edited by Jankec90; 07-14-2013 at 18:11.
Jankec90 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 01-30-2013 , 10:44   Re: [STEAM API] Simple php steam login in your site
Reply With Quote #2

People usually use an example to learn how to do something the right way, so you are responsible to show it the right way if you write an example.
  • Use curl if possible, it's faster imo
  • Use sessions, cookies are unsafe in the way shown
Yours sincerely
Impact
__________________

Last edited by Impact123; 01-30-2013 at 10:48.
Impact123 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-30-2013 , 11:15   Re: [STEAM API] Simple php steam login in your site
Reply With Quote #3

Quote:
Originally Posted by Impact123 View Post
Use sessions, cookies are unsafe in the way shown
As in you hook this up to sourcebans or something important, and somebody sets their cookies to be the owner's id. Right?
Mitchell is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 01-30-2013 , 13:26   Re: [STEAM API] Simple php steam login in your site
Reply With Quote #4

For example, yup.

Yours sincerely
Impact
__________________

Last edited by Impact123; 01-30-2013 at 13:27.
Impact123 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode