Hi
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
}