我看到CURLOPT_USERPWD可用于访问受保护的文件夹。但是在我的callback.php文件中,它没有CURLOPT_USERPWD。如何修改我的文件,添加CURLOPT_USERPWD以使其有效?
您可以在此处查看我的文件:
<?php
function callback_start() {
$yoururl = "http://abc.domain.com";
include "key.php";
$pass_array['key'] = $key;
$pass_array['domain'] = $_SERVER['SERVER_NAME'];
function confirm($url, $data) {
$options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => false, CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 50, CURLOPT_TIMEOUT => 50, CURLOPT_MAXREDIRS => 0,
CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYHOST => 0, );
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
$info = confirm($yoururl . "/folder/index.php", $pass_array);
if ($info['status'] == "2") {
return die("Suspended!");
}elseif($info['status'] == "3") {
return die("Incorrect");
}elseif($info['status'] != "1") {
return die("Error!");
}
}
?>
答案 0 :(得分:0)
这可能是一个延伸,但如果您在同一本地网络上运行服务器,则可以执行此操作:
Using .htaccess to mask a domain?
应用于此处:( Apache配置文件httpd.conf的食物)
<VirtualHost *:80>
ServerName private.abc.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://protected-site-local-ip:80/private/
ProxyPassReverse / http://protected-site-local-ip:80/private/
<Location />
Allow from all
</Location>
</VirtualHost>
由于PHP在本地系统上运行,因此访问代理站点没有问题(没有密码,但只能从本地网络访问)。确保您没有给代理的域名提供公共域名。
我还没有尝试过,但您可以直接从PHP转到本地网络上的文件吗? (例如http://10.149.2.1/www/private/stuff-you-need)?您可以完全绕过代理方法。
答案 1 :(得分:0)
嗯,我没有试过这个,但我的想法是你会这样做:
function confirm($url, $data) {
$options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => false, CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 50, CURLOPT_TIMEOUT => 50, CURLOPT_MAXREDIRS => 0,
CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_USERPWD => $username.":".$password, );
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}