How to create a URL redirector?

Asked

Viewed 594 times

-1

  • 1

    You could rephrase the question in order to dispense with the external link to be understood?

4 answers

5

I would also indicate doing this redirection in PHP, as the example below:

<?php
$url = $_GET['url'];
if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
    header('Location: '.$url);
} else {
    die('Não é uma url');
}

It is the most indicated because there you can record access metrics, such as date and time of access or even IP.

  • 1

    Always use exit; after a redirect, unless you want the code after the header() run. + 1 for your reply!

1

You can do it like this:

1) If you want to obfuscate your link, use the function base64_encode

base64_encode('http://google.com');

2) if you need to pass the parameter to the script, for example

http://meusite.com/redirecionar.php?l=aHR0cDovL2dvb2dsZS5jb20=

Pera catch the link inside the script. can use something like:

$link = base64_decode($_GET['l']);

3) To redirect, do not use the function header() if you are going to display some output before, it will generate an error, you need Javascript

window.location = '<?php echo $link; ?>';

0

A simple way to implement what you search with Javascript could be:

<html>
  <script>
    function redirect() {
      var match = /\?url=(.+)/.exec(window.location);
      if (match)
        window.location = match[1];
    }
  </script>
  <body onload="redirect();"></body>
</html>

Open this page as www.exemplo.com/redirect.htm?url=http://www.google.com/.

You can take advantage of the same idea to make the waiting code or similar things.

0


The page code itself can help you solve the problem. There appear the JS for you to use as a basis for your application.

here is the download URL:

function download() {
url = QueryString("url")
// Remove o "http://" caso exista (apenas para não colocar duas vezes)
url = url.replace("http://", "")
// Adciona o "http://"
url = "http://" + url
top.document.location = url
}
</script>

analyze the counter code

<script language="JavaScript">
//<![CDATA[
var xtx=20;
function IniciaRegressivo() {
if (xtx > 0) {
document.getElementById('botao').innerHTML = '<div class="protetor-botao"><a>Aguarde '+ 
x +' segundos</a></div>';
xtx = xtx - 1;
setTimeout("IniciaRegressivo();", 1000);
} else {
document.getElementById('botao').innerHTML = '<div class="protetor-botao"><a 
ef="javascript:download();">Fazer Download</a></div>';
}    }
//]]>
</script>

and in vc performs these functions. The code is well explanatory.

Browser other questions tagged

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