Is there a way to hide a url on a web page?

0

Let's break it down, I'm doing a site where I'm going to read a URL from the database and then I'm going to use it in an image, clicking on it (image) will open that URL (inside an iframe or in a new tab).

In the code, I have a page using HTML and PHP where I show the image with the hyperlink URL visible :

<!DOCTYPE html>
<html>
<head>

</head>
<body>
    <div> 
    <?php
        include ("connection.php");

        $sql = "SELECT * FROM table";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo "<div class=\"gallery\">";
                echo "  <a target=\"iframe1\" href=\"".$row["url"]."\" onclick=\"openiframe()\">";
                echo "    <img src=\"images\".$row["image"]."\" width=\"600\" height=\"400\">";
                echo "  </a>";
                echo "  <div class=\"desc\"><a href=\"".$row["url"]."\" target=\"_blank\">".$row["name"]."</a></div>";
                echo "</div>";
            }
        } else {
            echo "0 results";
        }

        $conn->close();
    ?> 
    </div>
</body>
</html>

The result of the previous code looks something like this:

Sofarsogood,nowwhatIintendedwasnottobevisibletheURL,inthefollowingimageImarkedwhatIsay:

Is there a way to hide the URL using eg PHP or some other way?

    
asked by anonymous 19.10.2017 / 16:28

2 answers

1

Previously, long ago, there was a method for this: window.status . You just need to put something like onmouseover="window.status='Olá'" on the link in the status bar of the browser instead of the link in href by hovering over the link " Hello ".

However, this method has been abolished and is no longer supported by more modern browsers.

One solution is to use the window.open method with onclick by opening the URL in a new tab (some browsers will open in a new window):

<a href="javascript:void(0)" onclick='window.open("destino.html","_blank")'>link</a>

In this way, " javascript: void (0) 'will appear in the browser instead of the URL, and the URL" destination.html "will open in a new tab / window (" _blank "). .

Using a function and deleting the script in the "developers tools":

<a href="javascript:void(0)" onclick='abrirURL("qualquercoisa")'>link</a>

or

<a href="javascript:abrirURL('qualquercoisa')">link</a>

Script with a id :

<script id="novaJanela">
function abrirURL(i){
    if(i == "qualquercoisa"){
        i = "destino.html";
    }
    window.open(i,i);
}

// aqui eu excluo virtualmente a tag script da página pelo id "novaJanela"
// não há problema em excluir essa tag, ela continuará funcionando
// porque já foi inserida na memória após o carregamento da página
window.onload = document.getElementById("novaJanela").outerHTML = '';
</script>
    
19.10.2017 / 18:26
0

You can use the file_get_contents function, and pass URL of your image on it. The function will return a base64 of your image, so you just put that base64 inside tag IMG , it would look something like this:

$base64 = file_get_contents('caminho_da_sua_imagem');
echo "<img src=\"data:image/png;base64, ".$base64."\">";

Remember that for each extension, you need to report on SRC :

  • PNG = <img src="data:image/png;base64, seu_base64">
  • JPG = <img src="data:image/jpg;base64, seu_base64">
  • GIF = <img src="data:image/gif;base64, seu_base64">
19.10.2017 / 16:40