duanbiao4035 2015-06-22 13:51 采纳率: 0%
浏览 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条)

报告相同问题?

悬赏问题

  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件
  • ¥150 求 《小魔指》街机游戏机整合模拟软件