<?php
/**
* Verifica se a url passada existe fazendo uma requisição a ela e caso ela retorne http code 200, significa que ela existe.
*/
function checkUrl($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return $httpCode == 200;
}
if (isset($_REQUEST['txt_url'])) {
$link = 'http://' . $_REQUEST['txt_url'] . '.dominio.com.br';
if (checkUrl($link)) {
header('Location: ' . $link);
} else {
echo 'Pagina nao existe.';
}
}
?>
<form action="" method="post">
<label for="txt_url">Seu texto:</label>
<input type="text" name="txt_url" value="">
<input type="submit" value="Ok">
</form>
Have you tried any code? Post the code for us to analyze.
– juniorb2ss
then actually not yet pq I have no idea where to start. If it were the opposite I would make a "cat". For example, I would send $url via get ($url=$_GET['url'];) and the other place header("Location: redirects.php? url=$url");
– Rodrigo B. Silva
Just use JS. By pressing the button you take the INPUT content, assemble a URL and redirect it.
– juniorb2ss
But how would you do it in js? I know how to redirect but take the content and add the url I already know. .
– Rodrigo B. Silva
and for example, if the url does not exist this way it will load the wrong page the same way, correct?
– Rodrigo B. Silva
It really needs to be done via php? a simple redirect can be done in javascript. So avoid traffic and server processes. Independent of being a very small process.
– Daniel Omine
It could be any language but only in JS would be better, but I still wouldn’t know how to do it. For example, if you could leave the form always fixed on the page and click on an iframe would be perfect, but there would be more blacksmithing. Since I don’t know how to do I think it would be too much to ask for so much.
– Rodrigo B. Silva