简体   繁体   English

浏览器如何允许下载php文件而wget没有? [MediaWiki安装]

[英]How does the browser allow downloading the php file while wget doesn't? [MediaWiki installation]

During the installation of MediaWiki, I had to download a file called LocalSettings.php . 在MediaWiki的安装过程中,我不得不下载一个名为LocalSettings.php的文件。 When I download it by clicking on the download link (which happens to be http://localhost/mymediawiki/mw-config/index.php?localsettings=1 ), it downloads a php file, but when I download it by "copy link address" and using 当我通过点击下载链接(恰好是http://localhost/mymediawiki/mw-config/index.php?localsettings=1 )下载它时,它会下载一个php文件,但是当我通过“copy”下载它时链接地址“和使用

$ wget URL -O output

it downloads a html file. 它下载一个html文件。

The following is the content of the index.php : 以下是index.php的内容:

The following is the content I get with wget : 以下是我用wget获得的内容:

Basically the page that offers the download link (which is http://localhost/mymediawiki/mw-config/index.php?page=Complete ), it seems. 基本上是提供下载链接的页面( http://localhost/mymediawiki/mw-config/index.php?page=Complete ),似乎。

The following are some of researches I had: 以下是我的一些研究:

But I don't understand how clicking on the "download the file" link DOES download the php file. 但我不明白如何点击“下载文件”链接DOES下载php文件。 This makes me wonder ther must be a way to download the php file with some bash commands like wget or curl . 这让我觉得必须是一种方法来下载php文件与一些bash命令,如wgetcurl

Please tell me how the browser is doing it, and any other way to do it through the termianl. 请告诉我浏览器是如何做的,以及通过termianl执行此操作的任何其他方式。

your browser has cookies, wget doesn't, it's almost certainly a file protected by cookies, only those with the correct (authentication?) cookies can access the file, wget can not. 你的浏览器有cookie,wget没有,它几乎肯定是一个受cookie保护的文件,只有那些有正确(认证?)cookie的人才能访问该文件,wget不能。 in chrome open the developer console, navigate to the Network tab, download the file in chrome, find the request in the network tab, right click on the tab and press "copy as curl", and you'll see what the request looks like with cookies, it'll look more like: 在chrome中打开开发人员控制台,导航到Network选项卡,在chrome中下载文件,在网络选项卡中找到请求,右键单击选项卡并按“copy as curl”,您将看到请求的样子饼干,它看起来更像是:

curl ' https://stackoverflow.com/posts/validate-body ' -H 'cookie: prov=5fad00f3-5ed3-bd3b-3a8a; 卷曲' https://stackoverflow.com/posts/validate-body ' -H“的Cookie:省= 5fad00f3-5ed3-bd3b-3a8a; _ga=GA1.2.20207544.1508821; _ga = GA1.2.20207544.1508821; sgt=id=e366-9d13-4df2-84de-2042; SGT = ID = e366-9d13-4df2-84de-2042; _gid=GA1.2.129666.1538138077; _gid = GA1.2.129666.1538138077; acct=t=Jyl74nJBTyCIYQq5mc2sf&s=StN3CVV2B5Opj051ywy7' -H 'origin: https://stackoverflow.com ' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-US,en;q=0.9' -H 'user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36' -H 'content-type: application/x-www-form-urlencoded; acct = t = Jyl74nJBTyCIYQq5mc2sf&s = StN3CVV2B5Opj051ywy7'-H'来源: https ://stackoverflow.com'- H'接受编码:gzip,deflate,br'-H'接受语言:en-US,en; q = 0.9 '-H'用户代理:Mozilla / 5.0(Windows NT 6.1; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 69.0.3497.100 Safari / 537.36'-H'内容类型:application / x-www - 形式进行了urlencoded; charset=UTF-8' -H 'accept: / ' -H 'referer: https://stackoverflow.com/ ' -H 'authority: stackoverflow.com' -H 'x-requested-with: XMLHttpRequest' --data $'body=your+browser+has+cookies%2C+wge&oldBody=&isQuestion=false' --compressed charset = UTF-8'-H'接受: / '-H'referer: https ://stackoverflow.com/'- H'权限:stackoverflow.com'-H'x-requested-with:XMLHttpRequest'--data $'body =你的+浏览器+有+ cookies%2C + wge&oldBody =&isQuestion = false' - 压缩

  • and if you run that command in bash, you'll probably be able to download the file from the terminal. 如果你在bash中运行该命令,你可能可以从终端下载该文件。

As you've seen in related questions, you can't download PHP source code just by requesting the file, at least as long as the HTTP Server has PHP extension enabled. 正如您在相关问题中看到的那样,您只能通过请求文件来下载PHP源代码,至少只要HTTP Server启用了PHP扩展即可。

But that by no means imply you can't download a PHP script given the right circumstances. 但这并不意味着在适当的情况下你无法下载PHP脚本。

You can have in the server a PHP script working as proxy to bypass PHP parsing and send you source code of any PHP file in the server. 您可以在服务器中使用PHP脚本作为代理来绕过PHP解析并向您发送服务器中任何PHP文件的源代码。 It just has to set up some headers and hand it to you with a simple readfile(filename) . 它只需要设置一些标题并用简单的readfile(filename)它交给你。 Of course, that is usually done after making sure that you are authorized. 当然,这通常是在确认您获得授权后完成的。

Also, the address of a link isn't always the address you are actually accessing when you click the link. 此外,链接的地址并不总是您单击链接时实际访问的地址。 It may contain a onclick action that overrides the href , and it can be placed there dynamically so you won't know about it even if you check the HTML source code. 它可能包含一个覆盖hrefonclick动作,它可以动态放置在那里,所以即使你检查HTML源代码也不会知道它。

One easy way to figure out what the link is actually doing is to press Ctrl+Shift+C in Firefox or Chrome, go to the Network tab, and click the link to see what it really is accessing. 找出链接实际执行操作的一种简单方法是在Firefox或Chrome中按Ctrl + Shift + C,转到“网络”选项卡,然后单击链接以查看其实际访问的内容。

I bet it is not accessing the file directly like you think. 我敢打赌,它不是像你想象的那样直接访问文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM