douaipi3965 2017-10-22 05:55
浏览 67


Consider this url:

So, my question is that how can i handle this get request?

To determine whether this hash is allowed to download or not?

  • 写回答

1条回答 默认 最新

  • dongwang6837 2017-10-24 06:49

    In my comment on your questions I suggested:

    You could use Apache's mod_rewrite to create a rule that sees something like file.mp3?hash=ajhfsjdhfjksf546sdf and redirects it to file.php?file=file.mp3&hash=ajhfsjdhfjksf546sdf. Then file.php will be able to handle the logic of checking access.

    Here is the code for .htaccess to accomplish this:

    RewriteCond %{QUERY_STRING} hash=(.*)$
    RewriteRule ^(.*)\.mp3$ file.php?file=$1.mp3&hash=%1 [L]

    This looks for a hash= value in the query string, and matches any called to (something).mp3. It snags the (something) and passes it as a value to the PHP script.

    Now if I call file.mp3?hash=ajhfsjdhfjksf546sdf, then file.php will have the following set:

    $_GET['file'] == 'file.mp3'
    $_GET['hash'] == 'ajhfsjdhfjksf546sdf'

    With these values, you can now run whatever check you'd like, and if it pases, deliver file.mp3 to the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 在线手电筒追加按钮JS
  • ¥15 调用函数时,无关变量的改变引起函数值的改变
  • ¥15 xy坐标转化为经纬度坐标
  • ¥15 一般三角模糊数的上界值和下届值取中值的多少比较合理?
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥20 Hbase启动失败,无法启动HMaster
  • ¥20 Lumerical FDTD solutions 中模型的相对阻抗,有效介电常数和有效磁导率的实部和虚部的数据如何获得?
  • ¥100 sql reporting service 远程smtp服务器配置支持
  • ¥15 ppyoloe_r带角度目标检测,loss_cls没法收敛
  • ¥15 淘宝交易指数如何解读,其关联的数据指标是什么