【问题标题】:How to implement one time password for download如何实现一次下载密码
【发布时间】:2018-03-01 11:02:42
【问题描述】:

我需要一些关于 php 的建议,我怎样才能使用户能够使用他们从我这里得到的密码一次性下载文件。

首先,我需要一些带有唯一密码列表的已连接数据库。 然后使用 php 我必须检测,如果密码用于下载 - 如果是,禁用它。

谁能帮帮我?

【问题讨论】:

标签: php one-time-password


【解决方案1】:

你只需要在数据库中维护一个字段,这样当用户下次点击时,它就不会被下载。

这就是我的做法: 当我发送链接时:

 $email_enc = base64_encode($check[0]->email_id);
    $id_enc = base64_encode($check[0]->id);
    $time = time();
    $url = $baseurl . "downloadfile?unq=" . $id_enc . "&em=" . $email_enc . "&tm=" . $time;

    $emaildata['message'] = "Hello $name,<br/><br/> Please <a href='$url'>Click</a> here to download your attachment.<br/><br/> Thanks,<br/>XYZ";
    sendmail($emaildata);
   //set status to 0

当用户点击链接时:

if ($_REQUEST['unq'] != '' && $_REQUEST['em'] != '' && $_REQUEST['tm'] != '') 
{
  $unique_id = base64_decode($_REQUEST['unq']);
  $u_email = base64_decode($_REQUEST['em']);
  $email_para = array(
    'id' => $unique_id
  );
  $check_avaibility = $this->User_model->getAnyData($email_para);
  if (!empty($check_avaibility)) 
  {
    $u_time = $_REQUEST['tm'];
    $cur_time = time();
    if ($cur_time - $u_time < 10800)
    {
      if(//check status to 0 only)
      {
       //download attachment
       //update the status as 1 that means link is not clickable next time
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 2018-04-24
    • 2011-03-19
    • 2015-06-16
    • 1970-01-01
    相关资源
    最近更新 更多