dpdbu24262 2011-09-19 16:03
浏览 32
已采纳

我需要整合两个站点,什么是携带登录信息的最佳方式?

So, I have two sites, sites A and B. I need to make B part of A. I did this by adding a module to A, and within that module, an iframe that contained a link to B. So, effectively speaking, B can still be accessed as a standalone site, but it can also be accessed through A. Now, both sites require a login to allow access. I need to bypass the login for site B when it is accessed through Site A. I managed to bypass it, but only if the two sites are hosted on the same server (I used session variables), but now I need to be able to bypass the login screen on B regardless of the server it is hosted on. So, how do I do this?

At first I thought cookies, but cookies are domain specific, the two sites might be hosted on separate domains.

Is there way a to use GET? So, Site A calls a url with the username written in the url, and then site B reads the url, parses it and logs in accordingly. I have no idea how I can implement this, what kind of url would I have to call, what kind of php code would Site B need, and lastly, how do you make something like this secure?

Thanks for all your help.

  • 写回答

1条回答 默认 最新

  • doumeng4400 2011-09-19 16:24
    关注

    Send a UUID with a hash to site B. The hash should be something that only both servers will know and can decode so something like the following should work.

    On site A

    <?php
    $salt = 'ashfiu8435t43434t fgfjgfgfuguSGDSBDY77;';
    $uuid = ''; // this should be set to the users ID
    $hash = sha1($salt . $uuid);
    ?>
    <a href="http://siteb.com?hash=<?php echo ($hash); ?>&uuid=<?php echo $uuid; ?>">Site B</a>
    

    On site B

    <?php
    $salt = 'ashfiu8435t43434t fgfjgfgfuguSGDSBDY77;';
    $uuid = $_GET['uuid'];
    $sent_hash = $_GET['hash'];
    $local_hash = sha1($salt . $uuid);
    
    if($sent_hash === $local_hash) {
       echo 'Logged in! Yay!';
    } else {
       echo 'Authentication failed';
    }
    

    You should make the hash more difficult to fake or figure out and make it expire after a given time so that people can't just save hashes and re-use them or pass them about. I have deliberately kept it simple to show this would work.

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

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条