Link Encrypting

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
scotty
Forum Newbie
Posts: 2
Joined: Fri Mar 28, 2008 2:11 pm

Link Encrypting

Post by scotty »

I was wondering how to encrypt links using php? I have a few links to images etc that I don't want others hotlinking to. For example Myspace used msplink to encrypt their links. Is something similar possible with php?

Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Link Encrypting

Post by Christopher »

Instead you could generate a unique ID each request and save it in the session. Then use a script as your image and pass it the ID. Check if they are the same, if yes display the image, if not show an error image.

Code: Select all

<?php
session_start();
$_SESSION['verify'] = uniqid();
?>
<img src="showimage.php?file=foo.jpg&verify=<?php echo $_SESSION['verify']; ?>"/>
(#10850)
scotty
Forum Newbie
Posts: 2
Joined: Fri Mar 28, 2008 2:11 pm

Re: Link Encrypting

Post by scotty »

Hi arborint. I am pretty new at this php stuff so i don't know how to do that. To clearify, I am wanting to just encrypt links and not the actual file location. The links are on my phpbb3 forum. Not sure if that will make a difference.
anto91
Forum Commoner
Posts: 58
Joined: Mon Mar 10, 2008 10:59 am
Location: Sweden

Re: Link Encrypting

Post by anto91 »

He made should have told you what to add to the showimage.php

but what happens in his code is that on the main page load he generates a php session with a unique id.

Then in the showimage you output image data IF the session is equvilent.
Post Reply