Search code examples
phpbase64url

Encode Image Url is this possible


How to hide an url with base64 like this?

<img src="show_image.php?url=aHR0cDovL2RvbWFpbi5jb20vaW1hZ2UuanBn">

Solution

  • In php you can encode in base64 with base64_encode(), and decode with base64_decode().

    So, in your html page script you can do:

    <?php
    $imageUrl = 'the image url';
    echo '<img src="show_image.php?url=' . base64_encode($imageUrl) . '">';
    

    And of course, you'll need to decode it on your show_image script:

    <?php
    $imageUrl = base64_decode($_GET['url']);
    $image = imagecreatefromstring(file_get_contents($imageUrl));
    header('Content-Type: image/png');
    imagepng($image);