lightopenid不发布会话变量

时间:2017-02-15 03:35:21

标签: php yii yii2 openid

目前正在处理一个shoutbox,并使用LightOpenID提供Steam登录方法。我也在使用Yii2框架。任何帮助将不胜感激!提前谢谢。

下面是index.php,它根据SteamID发布数据。

<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\LoginForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

$this->title = 'Dashboard';
$this->params['breadcrumbs'][] = $this->title;

require "steamauth/steamauth.php";

if(!isset($_SESSION['steamid'])) {

    echo('Hitting no steamid marker');

    $localUserName = "Guest";

    }  else {

    include ('steamauth/userInfo.php');

    $localUserName = ucfirst($_SESSION['steam_personaname']);
    };

if (!isset($_SESSION['steamid'])) {
    echo ("<div class='well'>
    <div class='jumbotron'>
    <h1>Login here.</h1>
    <p>This prevents x from having to store user passwords. Powered by <a href='http://www.steampowered.com'><strong>STEAM</strong></a>.</p>
    <p><a id='steamlogin' href='?r=user-record/index&login=1' class='btn btn-success btn-large loginButton'><span class='glyphicon glyphicon-log-in'></span> Login through Steam</a></p>
    </div>
    </div>");
    $this->title = 'Login';

} else { 

    echo("
        <div class='well'>
        <div class='jumbotron'>
        <h1>Dashboard</h1>
        <p>Hey there, <a href=". $_SESSION['steam_profileurl'] . "><strong>" . $_SESSION['steam_personaname'] . "</strong></a>. </p>
        <p><img src=" . $_SESSION['steam_avatarfull'] . "</img></p>
        <p>Steam ID: <strong>" . $_SESSION['steamid'] . "</strong></p>


        <p>
        <p><a id='steamlogout' href='?r=user-record/index&logout=1' class='btn btn-danger btn-large logoutButton'><span class='glyphicon glyphicon-log-out'></span> Disconnect</a></p>
        </div>
        </div>");
}
?>

这是授权文件,它使得它一直返回authURL,然后继续重定向回登录页面而不设置任何变量。期待它返回&#39; steamid&#39;。

ob_start();
if (isset($_GET['login'])){
    require 'openid.php';
    echo('login initiated');
    try {
        echo('try initiiated');
        require 'SteamConfig.php';
        $openid = new LightOpenID($steamauth['domainname']);

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

                $_SESSION['steamid'] = $matches[1];
                if (!headers_sent()) {
                    header('Location: '.$steamauth['loginpage']);
                    exit;
                } else {
                    ?>
                    <script type="text/javascript">
                        window.location.href="<?=$steamauth['loginpage']?>";
                    </script>
                    <noscript>
                        <meta http-equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
                    </noscript>
                    <?php
                    exit;
                }
            } else {
                echo "User is not logged in.\n";
            }
        }
    } catch(ErrorException $e) {
        echo $e->getMessage();
    }
}

1 个答案:

答案 0 :(得分:0)

您需要使用文件顶部session_start();的会话在所有文件中启动会话。

参考:

错误报告也会帮助您: