Answer the question
In order to leave comments, you need to log in
How to send data for authorization via HTTP Basic Authorization through a script?
It is necessary to authorize on the server using HTTP Basic Authorization using a PHP script .
So far I've only found this:
<?
//выделяем переменные, просто для удобства;
$login = 'login';
$pass = 'password';
$url = 'url';
$path = '/';
//устанавливаем соединение с сервером;
$sock = @fsockopen($url, 80, $errno, $errstr, 30);
if (!$sock) exit("Не смог соединиться");
$lenght = strlen($data); //длина данных;
$auth = base64_encode("{$user}:{$pass}"); //данные для аутентификации;
$request = <<<request
POST http://{$url} HTTP/1.0
Host:{$url}
Authorization: Basic {$auth}
Content-Type:text/xml
Content-length: {$lenght}
request;
$request .= $data;
$answ = '';
if(fwrite($sock,$request))
while(!feof($sock))
$answ.= fgets($sock);
fclose($sock);
header("Content-type: text/plain");
print($answ);
?>
HTTP/1.1 408 Request Time-out
Date: Fri, 13 Dec 2013 22:40:08 GMT
Server: Apache/2.2.16 (Debian)
Vary: Accept-Encoding
Content-Length: 306
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>408 Request Time-out</title>
</head><body>
<h1>Request Time-out</h1>
<p>Server timeout waiting for the HTTP request from the client.</p>
<hr>
<address>Apache/2.2.16 (Debian) Server at servername.ru Port 80</address>
</body></html>
Answer the question
In order to leave comments, you need to log in
curl --user name:password www.example.com
www.php.net/manual/en/book.curl.php
$curl = curl_init('http://www.example.com');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "name:password");
curl_exec($curl);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question