html — нет результата при аутентификации http через php curl

У меня есть веб-сервер, защищенный http. Я хочу войти на этот сервер1 через другой. Когда я использую этот URL: Http: // имя пользователя: пароль @ сервер1. Оно работает.

Теперь я хочу выполнить этот URL с другой веб-страницы в server2. Я использую Curl.

<?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?

0

Решение

Пытаться,

$username                ='username';
$password                ='password';
$yourEfforts             = array();
$yourEfforts['username']=$username; //stored in yourEfforts array.
$yourEfforts['password']=$password; //stored in yourEfforts array.
$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, $yourEfforts);//Your username and password
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
echo "<pre>";
var_dump(curl_exec($ch));//debug curl exec output
var_dump(curl_getinfo($ch));//debug curl info
var_dump(curl_error($ch));//debug curl error
$result=curl_exec ($ch);
echo $result ;
curl_close ($ch);

Надеюсь, поможет!

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector