我正在尝试使用openid与Steam来测试该功能是否有效。
我在localhost上使用Apache 2.2(我没有域名可以连接)。
我正在使用github repo here
我也在使用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();
}
}
?>
userInfo.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'];
?>
非常感谢帮助。
答案 0 :(得分:1)
解决了我的问题。这是我的Apache服务器的问题。再次下载软件,现在可以正常工作。