PHP Hide Files Real Location From Clients An Still Display Contents.

Learn how you can hide your files real location with PHP from your clients and still be able to display contents of those files.

Last Update: May 07, 2021

PHP Hide Files Real Location From Clients An Still Display Contents.

Hello friend, today we are going to use PHP and hide the real location of your files from clients. Suppose that you are a web developer and you don't want client to access your files or know where you placed them, then we are going to show you how you can do that by just using PHP.

Note that for this tutorial, we are going to use an image as an example to show you how you can hide real files location, but you can use this method to hide your images, music, video, CSS files, JavaScript files. I have listed type of contents that you can hide the real path of, as I have practically done so in other projects.

We will be using base64 encoding to display and hide real path of files content, by using base64 clients will only see some junk of code without the real source location.

As we stated that we will use an image as an example we will display the image without hiding its location and display it with location been hidden. Well lets get to it.


index.php

<?php
/*
    Author: Mr Parallel
    Tutorial: Hide Real File(s) Path
    Contact: stetcha@panthera-clan.co.za
*/
    function hidePath($source){
        /* Note that for the '$source' parameter, make sure to input the real location of a file.
           The location won't be visible to clients
        */
        $content_type = mime_content_type($source); //Get what type of content is been passed
        $data = file_get_contents($source);
        $base64 = "data:$content_type;base64," . base64_encode($data);
            
        return($base64);
    }
?>

<style>
    body{
        text-align: center;
    }
    h1{
        color: #007052;
    }
    img{
        max-width: 350px;
        margin-bottom: 80px;
    }
</style>

<!DOCTYPE html lang="en">
<html>
    
    <head>
        <title>Hide real location of images and scripts using php</title>
    </head>

    <body>
        <h1>Image without hidden location</h1>
        <img src="screen0.png" alt="Image without location been hidden"/>
        <h1>Image with hidden location</h1>
        <img alt="Image with hidden location" src="<?php echo hidePath("screen0.png");?>"/>
    </body>

</html>


From this code you will see that this will be the output:


As you can see, the image is still the same there's no difference, then lets inspect the images and see their resource location.

And now we can see that for the image with hidden location, the image "src" is just some chunk of unreadable code.


Well that's how you can hide your files real location, but bare in mind that this is not the only solution, there are other solutions outside this one.

Source Code: Download Source Code


Thank you for visiting the site.


Regards

Mr Parallel