Im making i photo sharint site
I want to give the ability for my users to prevent the public to acces their albums with a password. Then they can give the password to the ones they want to be able to see it.
To password protect their albums.
Im thinking something like this, cant test it on this computer, should work ok. but as im a php/mysql beginner i wanna hear what you experts think if theres a better way/approach
<h3>Albums</h3>
- id
- name
- owner
- password (if it isnt null the album is considered password protected)
<h3>The code</h3>
$id = isset($_GET['albumID']) ? intval($_GET['albumID']) : 0;
$result = mysql_query("SELECT * FROM albums
WHERE id = $id");
$row = mysql_fetch_object($result);
// IS it password protected?
if ($row->password != NULL) {
echo "This album is password protected.";
// User pressed "Enter"
if (!empty($_POST['password'])) {
$result = mysql_query("SELECT password FROM albums
WHERE password = '".mysql_real_escape_string($_POST['password'])."'");
// Was It right password?
if (mysql_num_rows($result) == 1)
{
$authed=1;
}
echo <<<EOT
<form method="post">
<input type="text" name="password" />
<input开发者_如何学运维 type="submit" value="enter" />
</form>
EOT;
exit;
} else $authed=1;
if $authed==1 {
// render albumimages etc
}
images itself must be protected too, not only album page.
and that could be harder to implement.
to get the idea, take a look at the Menalto gallery and http://shiftingpixel.com/2008/03/03/smart-image-resizer/
Also you need to set up a session after successful password entry.
With all these features it could be hard for a newbie. May be you have to look at ready made solutions
精彩评论