简体   繁体   English

在 PHP 中验证/绕过 .htaccess .htpasswd

[英]authenticate / bypass .htaccess .htpasswd in PHP

I've had a good look around here for articles relating to this and nothing I see seems to work.我已经仔细查看了与此相关的文章,但我看到的似乎没有任何效果。 Let me start by explaining my situation.让我先解释一下我的情况。

I have a load of files and folders (directories) inside a .htpasswd/.htaccess protected folder.我在 .htpasswd/.htaccess 保护的文件夹中有大量文件和文件夹(目录)。 These are sat on a Windows Server running xamp apache.它们位于运行 xamp apache 的 Windows Server 上。

On this server (and within this folder) I have a single .php page which pulls in database records & assets from with the folder & sub-folders.在这台服务器上(以及在这个文件夹中),我有一个 .php 页面,它从文件夹和子文件夹中提取数据库记录和资产。 The assets are organised, but all over the place.资产是有组织的,但无处不在。

I have a linux server with a php file and I am trying to embed that single php file using iframe ideally (as its easy for format).我有一个带有 php 文件的 linux 服务器,我正在尝试使用 iframe 理想地嵌入该单个 php 文件(因为它易于格式化)。 Issue is it's still asking me to provide the credentials to login to the .htaccess site.问题是它仍然要求我提供登录 .htaccess 站点的凭据。

I tried to create a php file above the password protected directory to load the php file within using file_get_contents however that still asked me for the password.我尝试在受密码保护的目录上方创建一个 php 文件,以使用 file_get_contents 加载 php 文件,但是仍然要求我输入密码。

I tried moving the file outside of the directory, but because all the assets are in the directory, it again asks for the login credentials...我尝试将文件移到目录之外,但由于所有资产都在目录中,因此它再次要求提供登录凭据...

WHAT DOES WORK什么有效

I tried editing the .htaccess to add my server IP however this didn't work as the iframe which loads it is a browser.我尝试编辑 .htaccess 以添加我的服务器 IP,但这不起作用,因为加载它的 iframe 是浏览器。 Adding my device public IP works which is a nice proof of concept, so I am thinking is it possible to make something serverside load the content?添加我的设备公共 IP 有效,这是一个很好的概念证明,所以我在想是否可以让服务器端加载内容? rather than an iframe which renders & loads browser side而不是呈现和加载浏览器端的 iframe

Alternatively, any workarounds I have missed?或者,我错过了任何解决方法?

Thanks谢谢

UPDATE 1更新 1

if i echo file_get_contents('local_file_path') I just get a screen of junk如果我echo file_get_contents('local_file_path')我只会得到一个垃圾屏幕

$fixture) { # check if today $today = date("Y-m-d"); $fixturedate = $fixture['date']; if ($fixturedate == $today) { $this_fixture = ['title'=>$fixture['title'], 'hometeam'=>$fixture['hometeam'], 'homegoals'=>$fixture['hometeamgoals'], 'homecards'=>$fixture['hometeamcards'], 'awayteam'=>$fixture['awayteam'], 'awaygoals'=>$fixture['awayteamgoals'], 'awaycards'=>$fixture['awayteamcards'], 'progress'=>$fixture['progress']]; array_push($game_array, $this_fixture); } } } ?>
@ " . date("G:i") . ""; ?>
No fixtures today..."; } echo ''; include "../connection.php"; //Connect to Database # GET Logos $lsql = "SELECT `fixture_list`.*,`logos`.* FROM `fixture_list` JOIN 

if I do a require 'local_file_path' it's better but none of the file paths match up as they're all relative in the original document如果我做一个require 'local_file_path'更好,但没有一个文件路径匹配,因为它们在原始文档中都是相对的

I have a few Ideas you can try:我有一些你可以尝试的想法:

Option1选项1

AuthUserFile /var/www/mysite/.htpasswd
AuthName "Please Log In"
AuthType Basic
require valid-user
Order allow,deny
Allow from 127.0.0.1
satisfy any

I've never personally tried this, so you may have to use the servers outbound IP (maybe).我从来没有亲自尝试过这个,所以你可能不得不使用服务器的出站 IP(也许)。 The idea is to allow access from a specific IP, localhost, without the login.这个想法是允许从特定 IP 本地主机访问,而无需登录。

Option2选项2

You could include the file by path (not url),您可以按路径(而不是 url)包含文件,

if I do a require 'local_file_path' it's better but none of the file paths match up as they're all relative in the original document如果我做一个 require 'local_file_path' 更好,但没有一个文件路径匹配,因为它们在原始文档中都是相对的

It's possible to set the working directory of PHP using chdir() .可以使用chdir()设置 PHP 的工作目录。

http://php.net/manual/en/function.chdir.php http://php.net/manual/en/function.chdir.php

bool chdir ( string $directory ) Changes PHP's current directory to directory. bool chdir ( string $directory ) 将 PHP 的当前目录更改为目录。

set_include_path() may also be an option. set_include_path()也可能是一个选项。

Option3选项3

You could use cURL and login, the example I found is by command line but it might also work using PHP's Curl.您可以使用 cURL 和登录,我发现的示例是通过命令行,但它也可以使用 PHP 的 Curl。

$output = shell_exec('curl -A "Mozilla" -L "http://user:password@domain.com/api/someapi.php"');

This may also work with file_get_contents, by adding the password and user to the url, however it will probably be recorded in the server access logs, which may or may not matter to you.这也可以与 file_get_contents 一起使用,方法是将密码和用户添加到 url,但是它可能会记录在服务器访问日志中,这对您来说可能重要也可能无关紧要。

It's always preferable to access files on your own server by path, it's much faster then doing a network request.通过路径访问您自己服务器上的文件总是更可取,它比执行网络请求要快得多。 And less visible log wise.并且不太明显对数。

I'm sure there are a few other tricks.我敢肯定还有其他一些技巧。

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

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