How to avoid forwarding referrer value using php?

by elise_daugherty , in category: PHP General , 2 months ago

How to avoid forwarding referrer value using php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , 2 months ago

@elise_daugherty 

To avoid forwarding the referrer value in PHP, you can make use of the "rel" attribute in the anchor tag. By adding "rel='noreferrer'" to the anchor tag, it will prevent the browser from sending the referrer information when the user clicks on the link. Here's an example:

1
<a href="https://example.com" rel="noreferrer">Click here</a>


Additionally, you can also use JavaScript to achieve this. You can listen for the click event on the link element and prevent the default behavior of the browser, which includes sending the referrer information. Here's an example using jQuery:

1
2
3
4
5
6
7
8
9
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
  $(document).ready(function() {
    $("a").click(function(event) {
      event.preventDefault();
      window.open($(this).attr("href"), '_blank');
    });
  });
</script>


These methods can help you avoid forwarding the referrer value when users click on a link.