Redirect only if there is a token but passing the last referer

1

I'm doing a redirection in site 1 to site 2 using this script built into the head of site 1:

<script>
window.location.href = 'http://www.sitio2.com/?redirect=true';
</script>

and then in site 2 in the index.php I include this in the head:

<?php
  if (isset($_GET["redirect"])) {
    $hash = $_GET["redirect"];
    if ($hash !== "") {
      header("Location: http://www.sitiofinal3.com");
      die();
    }
  }
?>

Well, if the user enters site 1 goes directly to site 2 and the latter will redirect him to a third and final site. On the other hand, if I access site 2 without going through site 1, it will not redirect to site 3. This is clear and works well. The problem is that when the user arrives at site 3, site 3 sees site 1 as referer and not site 2.

I need when the user lands on the final page (in the example, is page 3) the referer that is seen is site 2 and not 1 as it happens now. What I can do? It would be very helpful to me.

Thank you very much in advance.

    
asked by David Matas 24.05.2017 в 03:15
source

2 answers

2

You can redirect in site 2 with JavaScript as you have in site 1.

The code would be something like this:

<?php
  if (isset($_GET["redirect"])) {
    $hash = $_GET["redirect"];
    if ($hash !== "") {

        echo "<script>
                window.location.href = 'http://www.sitiofinal3.com';
              </script>";
    }
  }
?>

In this way, the redirection is done from the browser and should throw in the site 3 the correct referer.

    
answered by 24.05.2017 в 18:38
0

If you want the referer to leave only the domain of the site, you could choose to send the parameter by POST. In that case, to be able to redirect from site 1 to site 2, you should use a form.

The code would be something like this:

Site 1:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>

    var $form=$(document.createElement('form')).css({display:'none'}).attr("method","POST").attr("action","http://www.sitio2.com/");
    var $input=$(document.createElement('input')).attr('type','hidden').attr('name','redirect').val("true");
    $form.append($input);
    $("body").append($form);
    $form.submit();

</script>

Site 2:

<?php
  if (isset($_POST["redirect"])) {
    $hash = $_POST["redirect"];
    if ($hash !== "") {

        echo "<script>
                window.location.href = 'http://www.sitiofinal3.com';
              </script>";
    }
  }
?>
    
answered by 25.05.2017 в 21:07