Page 1 of 1

Image Lock Script

Posted: Sun Jun 01, 2003 12:33 am
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!

Posted: Sun Jun 01, 2003 8:31 pm
by curseofthe8ball
anyone?

Posted: Sun Jun 01, 2003 9:04 pm
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.

Posted: Sun Jun 01, 2003 9:37 pm
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...

Posted: Sun Jun 01, 2003 9:42 pm
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.

Posted: Sun Jun 01, 2003 10:33 pm
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,

Posted: Mon Jun 02, 2003 12:36 am
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

}
?>