PHP link protector to capture and encrypt and add a URL before

Asked

Viewed 755 times

-1

Ola would like to know how I can use Javascript or PHP to put this url https://protetor.com/?url= before the addresses of the download servers automatically I use these servers Skydrive, Clouddrive, Pcloud, Bitcasa, Meocloud, Lolabits, Google, Clouddriver I used Adfly it has a Javascript script that automatically adds the address at the beginning of these Urls to the address of the protector. With all this new protector do not have this kind of scripts.

AN EXAMPLE IN jQuery:

// Lista de bases de URLs dos servidores.
var urlsBases = ["meocloud.pt", "mega.co.nz", "outro.servidor.com"];

for (var i = 0; i < urlsBases.length; i++) {
var serverUrlBase = urlsBases[i];

// OBS: é necessário colocar entre aspas simples a url no filtro do jQuery 
por atributo.
$("a[href*='" + serverUrlBase + "']").each(function() {
    var urlProtegida = "https://protetor.com/?url=" + 
$(this).attr("href");

    $(this).attr("href", urlProtegida);
});
}

But there is some form in PHP to encode the ? url at the end ? in base 64

EXAMPLE:

https://protetor.com/?url=aHR0cHM6Ly91cGxvYWRici5jb20vOTBmZTExODRmZTkxNzBhNA==

To decode I already know, but not to encode... Someone knows as ?

1 answer

2


To convert a value to Base64, in the Javascript, just use the function window.btoa, for example: btoa($(this).attr("href")

Example:

/**
 * Executa a função após criação. Isso dispensará o uso do jQuery
 * dessa forma você poderá chamar, antes mesmos das execuções de
 * outros scripts.
 */
(() => {
  const urlsBases = ["meocloud.pt", "mega.co.nz", "outro.com"];

  for (let urlBase of urlsBases) {

    const anchors = document.querySelectorAll("a[href*='" + urlBase + "']");

    anchors.forEach(el => {
      let urlProtegida = "https://protetor.com/?url=" + btoa(el.getAttribute("href"))

      el.setAttribute("href", urlProtegida)

      console.log(urlProtegida)
    });
  }
})();
<a href="https://meocloud.pt/sdashdasda">meocloud<a>
<a href="https://mega.co.nz/hfghfghf">mega<a>
<a href="https://outro.com/121">outro<a>

In the PHP, you can use the function base64_encode. She will convert a string for coding Base64, for example:

<?php

$urls = [
    "https://meocloud.pt/sdashdasda",
    "https://mega.co.nz/hfghfghf",
    "https://outro.servidor.com/1gfdg5d4",
];

foreach($urls as $url) {
    echo "https://protetor.com/?url=" . base64_encode($url), PHP_EOL;
}

Demonstration: https://ideone.com/j2KR3V

  • In php, you can make it pick up the url automatically as in javascript ?

  • @Matheusvitor It is not possible to manipulate HTML with PHP. It is possible to manipulate if these URL come from a database. There it is possible to manipulate before, but before HTML is loaded.

  • Thank you helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.