PHP Link Protector to Capture and Encrypt and add a URL before

-1

Hello, I would like to know how I can use JavaScript or PHP to put this url https://protetor.com/?url= before the addresses of download servers automatically I use these servers SkyDrive, Clouddrive, Pcloud, Bitcasa, Meocloud, LolaBits, Google, Clouddriver I used the Adfly it has a script in JavaScript that automatically adds the address at the beginning of these URLs to the address of the protector. With all this new protector they 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 is there any way in PHP to encode the url? in the end ? in   base 64

EXAMPLE:

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

  

To decode I already know, but not to code ... Does anyone know   how?

    
asked by anonymous 19.04.2018 / 06:55

1 answer

1

To convert a value to Base64 , in JavaScript , just use the window.btoa function, 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 PHP , you can use the base64_encode function. It will convert a string to the base64 tag, 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;
}

Demo: link

    
19.04.2018 / 07:27