dongxin1999 2011-12-14 13:28
浏览 61
已采纳

PHP HybridAuth:如何重定向到所选社交网络的“允许”页面?

I'm having some issues with HybridAuth when I need to redirect "a non-registered user in my local database", to the selected social network: facebook, twitter, windows live, linkedin, openid, etc, more presiously to the "Allow" and "Cancel" page!?

Till now I've got this code going on:

try {
    // $via for instance can be: Twitter, Facebook, etc
    $hybridauth = new Hybrid_Auth( $myConfig );
    $via = ucfirst($via);
    $adapter = $hybridauth->authenticate( $via ); // from this line some redirecting accoures

    if( $hybridauth->isConnectedWith( $via ) ){
        $user = $hybridauth->authenticate($via)->getUserProfile();
    }

    $profile = Users::model()->findByAttributes(array(
        'networkName' => $via,
        'networkId' => $user->identifier,
    ));

    if(!is_null($profile)) {
        // do a login
    } else {
        // do a registration + login
    }
} catch(Exception $e) {
    echo "Error: please try again!";
    echo "Original error message: " . $e->getMessage();
    die();
}

I hope I've made my point clear. Thanks for all assistance in this matter!

  • 写回答

1条回答 默认 最新

  • doulang7699 2012-01-13 18:52
    关注

    The way I do is to store the provider and the provider identifier in a database, which seems to be the way you implemented as well.

    If the user does not exist, I create it and then redirect the user to the user profile editor. Otherwise I just redirect to the main page or dashboard.

    The provider data has all the required fields for creating a basic profile. If you need something else, redirect the user to a page with a form for him to complete the registration. Store anything else you need in SESSION or similar. You can use $hybridauth->restoreSessionData($_SESSION['HYBRID']) to keep the session on.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况