1

我正在尝试将 openid 与 Steam 一起使用来测试该功能是否有效。

我在 localhost 上使用 Apache 2.2(我没有要连接的域)。

我正在使用在这里找到的 github 存储库

我也在使用 Dreamweaver 编译代码并测试它是否有效。

但是,问题在于 Dreamweaver 不编译代码,它只是显示代码。

图片如下所示:

我的代码:

example.php(运行我的代码的文件)

<?php
    require ('steamauth/steamauth.php');  

?>
<html>
<head>
    <title>page</title>
</head>
<body>
<?php
if(!isset($_SESSION['steamid'])) {

    echo "welcome guest! please login \n \n";
    steamlogin(); //login button

}  else {
    include ('steamauth/userInfo.php');

    //Protected content
    echo "Welcome back " . $steamprofile['personaname'] . "</br>";
    echo "here is your avatar: </br>" . '<img src="'.$steamprofile['avatarfull'].'" title="" alt="" />'; // Display their avatar!

    logoutbutton();
}    
?>  
</body>
</html>

steamauth.php

<?php
ob_start();
session_start();
require ('openid.php');
$api_key = "XXXX"; //Insert API Key here!

function logoutbutton() {
    echo "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>"; //logout button
}

function steamlogin()
{
try {
    // Change 'localhost' to your domain name.
    $openid = new LightOpenID('http://localhost/');
    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'http://steamcommunity.com/openid';
            header('Location: ' . $openid->authUrl());
        }
    echo "<form action=\"?login\" method=\"post\"> <input type=\"image\" src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png\"></form>";
}

     elseif($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        if($openid->validate()) { 
                $id = $openid->identity;
                $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
                preg_match($ptn, $id, $matches);

                session_start();
                $_SESSION['steamid'] = $matches[1]; 

                 header('Location: '.$_SERVER['REQUEST_URI']);

        } else {
                echo "User is not logged in.\n";
        }

    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}
}

?>

用户信息.php

<?php

    $api_key = "XXXX"; // Insert API Key here!

    $urla = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $api_key; 
    $urlb = "&steamids=";
    $urlc = $urla . $urlb;
    $url = $urlc . $_SESSION['steamid'];
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($ch);
    curl_close($ch);
    $content = json_decode($content, true);

    $steamprofile['steamid'] = $content['response']['players'][0]['steamid'];
    $steamprofile['communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
    $steamprofile['profilestate'] = $content['response']['players'][0]['profilestate'];
    $steamprofile['personaname'] = $content['response']['players'][0]['personaname'];
    $steamprofile['lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
    $steamprofile['profileurl'] = $content['response']['players'][0]['profileurl'];
    $steamprofile['avatar'] = $content['response']['players'][0]['avatar'];
    $steamprofile['avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
    $steamprofile['avatarfull'] = $content['response']['players'][0]['avatarfull'];
    $steamprofile['personastate'] = $content['response']['players'][0]['personastate'];
    $steamprofile['realname'] = $content['response']['players'][0]['realname'];
    $steamprofile['primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
    $steamprofile['timecreated'] = $content['response']['players'][0]['timecreated'];
?>

帮助将不胜感激。

在此处输入图像描述

4

1 回答 1

1

解决了我的问题。这是我的 Apache 服务器的问题。再次下载该软件,现在它可以工作了。

于 2014-08-26T10:14:47.020 回答