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.

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

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求