/    Sign up×
Community /Pin to ProfileBookmark

Encoded/Encrypted Image Names Suggestions Help!!

Hello,
So I’m trying to make it so the client doesn’t see

[code=html]<div class=”image” style=”background-image: url(images/210.jpg)”>[/code]

But instead sees something like:

[code=html]<div class=”image” style=”background-image: url(images/r2re6er24y.jpg)”>[/code]

Just a random string of characters, it’s to stop the user looking ahead for image 211.jpg or 320.jpg etc.

currently the jpg number is called by

[code=php]$iddate = date(‘z’)+1;[/code]

If anyone has any ideas on how to do this it would be appreciated.
I was thinking something with temporary images but I don’t know how or if that would work?

Many Thanks ?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@rootJul 29.2013 — Sounds to me like you need to have the actual images renamed to a seemingly random sequence, a database that has the original name / number and what it is renamed to so you are able to know via a script what to serve up.

I really don't see why you would need to "Protect" these images, 99% of web users wouldn't have the technical knowledge on how to look ahead or couldn't care less about trying.

Also, if somone wants it, they would only need to take a screen shot of it!
Copy linkTweet thisAlerts:
@jswsauthorJul 29.2013 — The images are in numerical order (badly explained sorry) so they could easy all be seen.

I'm not worried about people downloading them, and i agree most users wouldn't know how to but I'm trying to stop users who do how to use google chromes inspector from seeing the future images, as the images change daily.

Maybe I'm being a bit paranoid but I just think it's a good thing to do.
Copy linkTweet thisAlerts:
@rootJul 30.2013 — How many images are we talking about?
Copy linkTweet thisAlerts:
@NogDogJul 30.2013 — If it's truly important for users to not be able to guess related image names, you could make use of PHP sessions along with an image server script.

Main script:
[code=php]
<?php
session_start();
$_SESSION['images'] = array(
'img1' => array(
'id' => uniqid('IMG', true),
'path' => $_SERVER['DOCUMENT_ROOT'].'/images/img_1.jpg'
),
'img2' => array(
'id' => uniqid('IMG', true),
'path' => $_SERVER['DOCUMENT_ROOT'].'/images/img_2.jpg'
)
);
?>
<img src='show_image.php?img=<?php echo $_SESSION['images']['img1']['id']; ?>' alt='' />
<img src='show_image.php?img=<?php echo $_SESSION['images']['img2']['id']; ?>' alt='' />
[/code]

show_image.php:
[code=php]
<?php
session_start();
if(!empty($_SESSION['images'])) {
foreach($_SESSION['images'] as $key => $data) {
if($data['id'] == $_GET['img']) {
header('Content-Type: image/jpeg');
readfile($data['path']);
exit;
}
}
}
header("HTTP/1.0 404 Not Found");
[/code]


This is just a rough cut at it: sure it could be cleaned up a bit. ?
Copy linkTweet thisAlerts:
@rootJul 30.2013 — Is it important that the images are sequential or would a random image picked be ok?
Copy linkTweet thisAlerts:
@jswsauthorJul 30.2013 — 365 images, and they have to be in order
Copy linkTweet thisAlerts:
@jswsauthorJul 30.2013 — Great thanks i'll give this a go
Copy linkTweet thisAlerts:
@rootJul 30.2013 — An alternative way of securing the images would be to have a folder outside of the main folder, something that can't be predicted. Using a shell script that calls a PHP script to then move the next image in to the folder for display making it impossible to obtain a future image.

I used this principle for a picture of the day script that needed two things, change over at 9pm and to be non-predictable before or after display.
×

Success!

Help @jsws spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...