【发布时间】:2016-02-29 11:43:52
【问题描述】:
我有一个由 http 保护的 Web 服务器。我想通过另一个服务器登录到这个 server1。当我使用这个网址时:http://username:password@server1。有用。
现在我想从 server2 中的另一个网页执行这个 url。我正在使用卷曲。
<?php
$username='username';
$password='password';
$URL='http://server1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec ($ch);
echo $result ;
curl_close ($ch);
?>
这对我不起作用。我只有使用 http 登录的弹出窗口。我的 php 页面有什么问题?
【问题讨论】:
标签: php html apache curl basic-authentication