Password protect user image album
Posted
by Poland Rocks
on Stack Overflow
See other posts from Stack Overflow
or by Poland Rocks
Published on 2010-04-18T19:18:42Z
Indexed on
2010/04/18
19:23 UTC
Read the original article
Hit count: 167
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
Albums
- id
- name
- owner
- password (if it isnt null the album is considered password protected)
The code
$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 <<
<form method="post">
<input type="text" name="password" />
EOT;
exit;
} else $authed=1;
if $authed==1 {
// render albumimages etc
}
© Stack Overflow or respective owner