请问怎么让服务器上的所有文件带cookies才能访问下载?
请问各位大神,怎么才能让服务器上的文件必须要在URL包含cookies才能下载?
特别是是PHP重定向到真实文件后(PHP的方法我试过了,但是不能满足需求,需要的是哪怕PHP访问中携带了cookies,然后重定向到真实文件了,也需要带cookies才能下载真实文件)
比如像这个:
http://gdl.lixian.vip.xunlei.com/download?fid=0hR2BkWuxG+yu8/SSvHED9qPY3qIM6UBAAAAAPgVMM+tcuZfzsSdkpa5AVaDBXss&mid=666&threshold=150&tid=2D7127D9AC515342BBCF3C2534A28B6E&srcid=4&verno=1&g=F81530CFAD72E65FCEC49D9296B9015683057B2C&scn=t13&i=F81530CFAD72E65FCEC49D9296B9015683057B2C&t=1&ui=352085248&ti=749121079740928&s=27603848&m=0&n=01397CB40C657475702D58903A2D786C384F549C3A00000000&ff=0&co=7146348578E47321F9ADCDC2E65E5373&cm=1&pk=lixian&ak=1:1:6:4&e=2000000000&ms=10485760&ck=7D925ECC1C9C2CD1098D37BAE3D249E3&at=BFBB6AE6FDC257D3BC3A9FDBFAE45212
通过cookies验证后,重定向到:
http://vod39.t6.lixian.vip.xunlei.com:443/download?fid=vlMMl5rBhEpw40dAJIWIAzFss/IbL0I1AAAAAGp5LQx3uSW+VWah1LGOGJx68Tey&mid=666&threshold=150&tid=7A76D65FCFBEDD0710723B8E9472CF47&srcid=4&verno=1&g=6A792D0C77B925BE5566A1D4B18E189C7AF137B2&scn=t6&i=D4FDF4149CF91CA34FC1A528291BA4D4&t=4&ui=346853248&ti=767920006498817&s=893529883&m=0&n=01226220F8D6E42E482500D46D34B8DFC784E7348CA2CBABD7B71F892F34000000&ff=0&co=907FCD65B217061FF4D04BDEBFBD25D5&cm=1&pk=lixian&ak=1:0:2:3&e=2000000000&ms=10485760&ck=3C1C62B8C80D6C0C47C833D5A92DEF1D&at=D9AD4F55BC8C22C248A75E6E2459686E&k=1&ts=1410592408
还是需要带cookies才能下载这个文件。
(第二个url好像不是PHP的,因为下载的文件真实地址就是这个,没有再经过跳转和重定向了)
(url只是举例,访问不了的)
怎么实现这样的?
服务器是nginx/linux
回复内容:
请问各位大神,怎么才能让服务器上的文件必须要在URL包含cookies才能下载?
特别是是PHP重定向到真实文件后(PHP的方法我试过了,但是不能满足需求,需要的是哪怕PHP访问中携带了cookies,然后重定向到真实文件了,也需要带cookies才能下载真实文件)
比如像这个:
http://gdl.lixian.vip.xunlei.com/download?fid=0hR2BkWuxG+yu8/SSvHED9qPY3qIM6UBAAAAAPgVMM+tcuZfzsSdkpa5AVaDBXss&mid=666&threshold=150&tid=2D7127D9AC515342BBCF3C2534A28B6E&srcid=4&verno=1&g=F81530CFAD72E65FCEC49D9296B9015683057B2C&scn=t13&i=F81530CFAD72E65FCEC49D9296B9015683057B2C&t=1&ui=352085248&ti=749121079740928&s=27603848&m=0&n=01397CB40C657475702D58903A2D786C384F549C3A00000000&ff=0&co=7146348578E47321F9ADCDC2E65E5373&cm=1&pk=lixian&ak=1:1:6:4&e=2000000000&ms=10485760&ck=7D925ECC1C9C2CD1098D37BAE3D249E3&at=BFBB6AE6FDC257D3BC3A9FDBFAE45212
通过cookies验证后,重定向到:
http://vod39.t6.lixian.vip.xunlei.com:443/download?fid=vlMMl5rBhEpw40dAJIWIAzFss/IbL0I1AAAAAGp5LQx3uSW+VWah1LGOGJx68Tey&mid=666&threshold=150&tid=7A76D65FCFBEDD0710723B8E9472CF47&srcid=4&verno=1&g=6A792D0C77B925BE5566A1D4B18E189C7AF137B2&scn=t6&i=D4FDF4149CF91CA34FC1A528291BA4D4&t=4&ui=346853248&ti=767920006498817&s=893529883&m=0&n=01226220F8D6E42E482500D46D34B8DFC784E7348CA2CBABD7B71F892F34000000&ff=0&co=907FCD65B217061FF4D04BDEBFBD25D5&cm=1&pk=lixian&ak=1:0:2:3&e=2000000000&ms=10485760&ck=3C1C62B8C80D6C0C47C833D5A92DEF1D&at=D9AD4F55BC8C22C248A75E6E2459686E&k=1&ts=1410592408
还是需要带cookies才能下载这个文件。
(第二个url好像不是PHP的,因为下载的文件真实地址就是这个,没有再经过跳转和重定向了)
(url只是举例,访问不了的)
怎么实现这样的?
服务器是nginx/linux
第二个可能是PHP的,
实现方式是验证,
PHP验证,PHP验证完了之后就输出文件内容,验证不通过就输出错误信息或者不输出东西。
别再跳转了 验证完cookie合法之后直接返回文件
不大可能实现应用程序服务器规则来控制,一般是php验证后跳转到真实地址。
用拦截器验证先
以前我曾经找人用C写了一个Nginx 扩展来用。
现在可以用Lua简单实现了。
nginx可以实现x-sendfile,把下载目录设置为internal即可
http://wiki.nginx.org/XSendfile
http://kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/

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











Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

Handling high DPI display in C can be achieved through the following steps: 1) Understand DPI and scaling, use the operating system API to obtain DPI information and adjust the graphics output; 2) Handle cross-platform compatibility, use cross-platform graphics libraries such as SDL or Qt; 3) Perform performance optimization, improve performance through cache, hardware acceleration, and dynamic adjustment of the details level; 4) Solve common problems, such as blurred text and interface elements are too small, and solve by correctly applying DPI scaling.

macOSandLinuxbothofferuniquestrengths:macOSprovidesauser-friendlyexperiencewithexcellenthardwareintegration,whileLinuxexcelsinflexibilityandcommunitysupport.macOS,developedbyApple,isknownforitssleekinterfaceandecosystemintegration,whereasLinux,beingo

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

macOS and Linux have their own advantages in compatibility and user experience. macOS has excellent compatibility within the Apple ecosystem, and the user experience is simple and intuitive; Linux has outstanding hardware compatibility and software flexibility. The user experience varies from distribution to distribution, emphasizing personalization and control.
