Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySecurity and Blocking

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Keeping Image Location Secret

Generally, when the source code of a web page is viewed, the URLs of images are visible.

If you have reason to keep the URL of an image secret, this article describes one way to do it.

One reason to keep the URL of an image secret would be to keep people from linking to your image in order to display it in their own web pages. Another reason would be to prevent people from linking to your image at their social media accounts.

Note that the method presented here works only with PHP web pages. It will not work with email reading software. PHP just doesn't work in email.

Here is an example:

Willmaster logo

To hide the image URL, make the image tag as follows (two items need to be customized).

<img
src="data:image/IMAGE_TYPE;base64,<?php echo(base64_encode(file_get_contents('IMAGE_URL'))) ?>" 
style="max-width:100%" 
alt="my image">

Two items in the format need to be replaced, IMAGE_TYPE and IMAGE_URL:

  1. Replace IMAGE_TYPE with png, gif, or jpeg, depending on the type of image you will be publishing.

    You can determine the image type by the file name extension of the image to be published. If the file name extension is png (as in myimage.png) then replace IMAGE_TYPE with png. If the file name extension is gif then replace IMAGE_TYPE with gif. And, if the file name extension is jpg or jpeg then replace IMAGE_TYPE with jpeg.

  2. Replace IMAGE_URL with the URL of the image to be replaced.

The image URL will not show in the web page source code because it is part of the PHP code. Anything the PHP code publishes is published with the web page. But the PHP code itself is removed from the web page when the PHP code is processed at the server.

Here is the image tag of the above example.

<img src="data:image/gif;base64,<?php echo(base64_encode(file_get_contents('https://www.willmaster.com/images/wmlogo_icon.gif'))) ?>" 
style="max-width:100%" 
alt="Willmaster logo">

After the PHP code in the above example runs, this is what would be seen in the source code of the web page.

<img src="data:image/gif;base64,R0lGODlhMgAyAOYAAEub4KzQ8fn7/FWh4pnG7WKbzdvb21OGsom965ubm7za89fX16LM77PV8uPj41yk45HC7GSp5YWFhVZ4lSKE2Xy152pqa4S66nKw5kOX3+3t7fHx8Xi051OVzaqqqi2K2zqR3aGhoev0/EaJw3p6eqfO8Gus5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aHjGMS3xgj5QAAAYgIAMtsnNbm4TAhgAAAX68IJptkITnPBDBIrgAgK4kwAuKEIE/NCJVZgTHIhQBCMcAQlJUGKagQAAOw==" 
style="max-width:100%" 
alt="Willmaster logo">

An img with base64-encoded data readily publishes an image in browsers. When the PHP code converts the image to base64 encoding for the web page, the URL is no longer necessary.

It is an effective method for hiding the URLs of images on the web page.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC