Image Lock Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
curseofthe8ball
Forum Commoner
Posts: 73
Joined: Sun Jun 01, 2003 12:33 am

Image Lock Script

Post by curseofthe8ball »

I'm looking for help on building a script that will allow users to lock pictures that they have uploaded to my site. Once an image is locked, it isn't viewable by anyone unless they have the password (which is set when the image is locked) to unlock the image.

Anyone have some ideas on how to go about this or a site that has code similar to this that could help me out?

Thanks in advance!
curseofthe8ball
Forum Commoner
Posts: 73
Joined: Sun Jun 01, 2003 12:33 am

Post by curseofthe8ball »

anyone?
SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

Are you using a database on the backend? If so, you could store the image name into the database as well as another column to indicate Locked or Unlocked. Then query the database whenever an image is attempting to be viewed and request a password if the Lock is set.
Doolittle
Forum Newbie
Posts: 19
Joined: Sun May 04, 2003 11:45 pm

Post by Doolittle »

Even easier, rename the file for when its locked and when it isn't... add a "_lock" to the end of the filename when its locked, and remove it when its not... then grab the file name without the extension, explode it by "_" and check to see if "lock" comes up in the array...
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

How would the image normally be accessed? Is this simply to stop "hot-linking" to images displayed on your site or is this something else?

Phil J.
curseofthe8ball
Forum Commoner
Posts: 73
Joined: Sun Jun 01, 2003 12:33 am

Post by curseofthe8ball »

The image filename is stored in the database currently. The PHP script tells it the path for the images directory and pulls the images based on filename.

What I'm trying to provide my users is the following:

They log into the site and goto their "Manage Photo Album" page. I'd like them to be able to password-protect any image(s) they feel necessary. This could be done via a text box underneath each image, for example.

If an image is password-protected it would display a generic graphic (something with a lock on it which I will create) to the general public. For the general public to be able to view the image, they would need the password to type into the box underneath the locked image. This would "unlock" the image.

Does this better explain what I'm looking to do? Ask any questions you need to better help me! Thanks,
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

If, as mentioned above, you add a column "locked_status" (0 or 1) and "password" try something approximately like this:

Code: Select all

<?php
// query db for image data..

IF ($locked == 0 OR $_POST['password'] == $password) {

    echo '<img src="..etc..">';

} ELSE {

    // display the form, locked image etc

}
?>
Post Reply