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条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?