duanbiao4035 2015-06-22 13:51
浏览 23
已采纳

PHP将域重定向到正确的域

I have two websites (domain1.com and domain2.com) with link button to basedomain.com website. In the basedomain.com I have one button to link back to the domain1.com

How I can redirect the users back to the website from which they came (domain1.com or domain2.com)

in basedomain.com I have a simple a href link:

<a href="http://domain1.com/" >Go back to Homepage</a>
  • 写回答

4条回答 默认 最新

  • duanhe6799 2015-06-22 14:02
    关注

    Add the link of the 'from' domain to your basedomain link like this:

    <a href="http://basedomain.com?from=domain1.com">
    

    Optional you can add some security to your link to verify that the 'from' part isn't altered, using HMAC. Or match the 'from' value at you base domain against a whitelist that contain the possible 'from' URL's.

    Hope this helps?

    EDIT

    Easiest way for now is to go with the whitelist variant. To do that, you have to do the following steps:

    1. Create a link to the basedomain from each (sub)domain like i've done above.
    2. The 'from' var contains the identifier of the current domain, for example the name (domain1.com)
    3. Build an array on your basedomain containing the valid enrties like this:

      $validDomains = [
          'domain1.com' => 'http://www.domain1.com/',
          'domain2.com' => 'http://www.domain2.com/',
          ....
      ];
      
    4. Building the back link on your base domain, start with checking the 'form' key against the validDomains. If the key exists, add the value of the validDomains as href link:

      $linkForYourHref = null;
      if (!empty($_GET['form']) && isset($validDomains[$_GET['form']))  {
          $linkForYourHref = $validDomains[$_GET['form'];
      }
      
      
      //button code
      if (!is_null($linkForYourHref))   {
           //link to $linkForYourHref
      }
      

    An another options is to authenticate your 'from' part of the basedomain link by adding a hash to the URL like this:

    <a href="http://basedomain.com?from=domain1.com&key=theHMACkey">
    

    See Paragonie for more info about that

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行