0

So I'm trying too make a steam login button for my site but it doesnt redirect to were I want to. Instead it just directs the user to a plain site with the users name and a log out button. I did not write this code I just copied of someone else just to try it. I'm trying to directing it back to index.php but it does not want too. Here is the code:

<?php
                        error_reporting(E_ERROR | E_PARSE | E_WARNING);

$user = new user;
$user->apikey = ""; // put your API key here
$user->domain = "localhost/index.php"; // 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);// put your 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;
}




?>

I removed the Apikey because I dont know if its save just to put it online to everyone to see like this. Thanks everyone :) have an awesome day. Sorry for my grammar my english isnt that good. Thanks again :D

Massaxe
  • 33
  • 2
  • 8

1 Answers1

0

I use the same code for my steam website See here.

            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;

In that area of code, there should be a fix. I cant seem to find my php for it, since I made mine pretty complicated with 2 php links and using frames to connect them with one and other.

As you stated

{
print('<form method="post"><button title="Logout" name="logout">Logout</button></form>');
echo $user->GetPlayerSummaries($_COOKIE['steamID'])->personaname; 
}

Mine is made like this, with the login/logout button loaded in with this php code. Not really sure if this will help you! If you use this code, make sure that you have the allow_url_fopen enabled for the signinout website.

$sign_inout = file_get_contents('http://kuramacraft.net/steam/signinout.php');

echo $sign_inout;

Thanks for taking your time for reading this!