密码保护用户图像相册

时间:2010-04-18 19:18:42

标签: php mysql

我正在制作我的照片sharint网站

我想让我的用户能够阻止公众使用密码访问他们的相册。然后他们可以给他们希望能够看到的密码。

用密码保护自己的相册。

我在想这样的东西,不能在这台电脑上测试它,应该可以正常工作。但作为一个php / mysql初学者我想听听你的专家认为如果有更好的方式/方法

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

1 个答案:

答案 0 :(得分:0)

图像本身也必须受到保护,而不仅仅是相册页面 而这可能更难实施。

要了解这个想法,请查看Menalto画廊和http://shiftingpixel.com/2008/03/03/smart-image-resizer/

您还需要在成功输入密码后设置会话 有了所有这些功能,新手可能会很难。可能你必须看看现成的解决方案