一个下载地址防盗的判断 大牛进来看下!
两个网站 一个主站 一个上传用的子站
主站的download.php 为下载页面
子站的down.php为下载链接
必须通过download.php的下载点击链接才能下载
为了防止用户直接访问 子站/down.php?fileid=1能下载到该文件 做了下面的判断
download.php 增加一个哈希值
$hash = strtoupper(md5('downloadkey'.date('ymdh')));
down.php 也增加一个哈希值
$hash2 = strtoupper(md5('downloadkey'.date('ymdh')));
down.php判断
if($hash<>$hash2){ header("Content-Type: text/html; charset=utf-8"); echo '文件ID: '.$file_id.'<br>'; echo '['.$file_name.'] 文件地址已过期,请返回下载地址重新下载。<br><br>如果仍然出现此问题,请联系管理员<br><br>'; if($pd_gid==1){ echo '<br><br>---------- 以下内容 管理员可见 ---------- <br>'; echo '文件HASH:<font color=blue>'.$hash.'</font><br><br><br>'; echo '文件HASH2:<font color=blue>'.$hash2.'</font><br>'; }
当时这样会有一个问题 就是当用户在20:59:59''的时候访问的下载页面,然后点击下载了
但是点击之后时间是21:00:01了,这样就造成了哈希值不一样,然后就不能下载,要返回重新下载一下就可以
如何解决呢。。
回复讨论(解决方案)
怎么木有人呢!
上面的是用时间来生成哈希值的 还有其他方法能防止吗
生成的 $hash 宜通过 cookie 传递并设有不太长的有效期,同时保存于 session 中
检查时不重新生成,而只检查 cookie 中是否有,并且与 session 中的对比
就同校验码一样
生成的 $hash 宜通过 cookie 传递并设有不太长的有效期,同时保存于 session 中
检查时不重新生成,而只检查 cookie 中是否有,并且与 session 中的对比
就同校验码一样
找到个简单点的方法
if(strpos($_SERVER['HTTP_REFERER'],'http://www.domain.com') == 0)
通过判断来路地址判断 不知道是否可行
生成的 $hash 宜通过 cookie 传递并设有不太长的有效期,同时保存于 session 中
检查时不重新生成,而只检查 cookie 中是否有,并且与 session 中的对比
就同校验码一样
找到个简单点的方法
if(strpos($_SERVER['HTTP_REFERER'],'http://www.domain.com') == 0)
通过判断来路地址判断 不知道是否可行
这个可以伪造
HTTP_REFERER 是可以伪造的
你可以参考下basic认证。
反过来,模拟浏览器也是一个课题。所以这是个道高一尺魔高一丈的问题。防盗只能防止正常的盗链,对于使用程序模拟浏览网页的话没法绝对防止。
所以建议防君子不防小人,使用referer防盗链。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
