php获取浏览器地址然后防盗链,刷新后便获取不到地址,请问是怎么回事啊
我的x.php代码如下。这个代码的大概意思是:我用一个网站引用另外一个网站的资源。
我的网站是http://www.123.com 和 http://www.abc.com
如果我输入http://www.123.com/x.php/love.mp3,实际上打开的是
http://www.abc.com/abc/love.mp3。下面代码完全可以实现了。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
header("content-Type: text/html; charset=Utf-8");
$SERVER=$_SERVER["REQUEST_URI"];
preg_match("/php\/([\s\S]+)\.mp3/",$SERVER,$url);
$urlname=$url[1];
$downurl='http://www.abc.com/abc/'.$urlname.'.mp3';
header("location:$downurl");
?>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
网页中的播放器可以正常播放http://www.123.com/x.php/love.mp3
后来我加入了防盗链,防下载,代码:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
header("content-Type: text/html; charset=Utf-8");
$SERVER=$_SERVER["REQUEST_URI"];
preg_match("/php\/([\s\S]+)\.mp3/",$SERVER,$url);
$urlname=$url[1];
$downurl='http://www.abc.com/abc/'.$urlname.'.mp3';
$url = $_SERVER["HTTP_REFERER"]; //获取完整的来路URL
$str = str_replace("http://","",$url); //去掉http://
$strdomain = explode("/",$str); // 以“/”分开成数组
$domain = $strdomain[0]; //取第一个“/”以前的字符
if ($domain=="www.123.com"){
header("location:$downurl");
}
if ($domain==""){
header("location:http://www.123.com/daolian.mp3");
}
if ($domain!="www.123.com"){
header("location:http://www.123.com/daolian.mp3");
}
?>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
修改完成后,防盗链防下载是实现了,在网页中的播放器播放http://www.123.com/x.php/love.mp3,却播放不了,请问这是代码究竟是什么地方出了问题啊。

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


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

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
