matrix717
asked on
How to send a header with a username & password
Look, what I'm doing is posting values and retreiving the HTML of that page where I'm posting them to
<?
function sendToHost($host,$method,$ path,$data ,$useragen t=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host,80);
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-url encoded\n" );
fputs($fp, "Content-length: " . strlen($data) . "\n");
if ($useragent)
fputs($fp, "User-Agent: MSIE\n");
fputs($fp, "Connection: close\n\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
return $buf;
}
echo sendToHost('www.domain.com','post','/va/post.php','var1=diana');
?>
My problem is that I want to use this function but to a page that I usually access like this http://user:pass@www.domain.com/va/ppp.php
It uses authentication... How can I send the username and password values?
<?
function sendToHost($host,$method,$
{
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host,80);
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-url
fputs($fp, "Content-length: " . strlen($data) . "\n");
if ($useragent)
fputs($fp, "User-Agent: MSIE\n");
fputs($fp, "Connection: close\n\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
return $buf;
}
echo sendToHost('www.domain.com','post','/va/post.php','var1=diana');
?>
My problem is that I want to use this function but to a page that I usually access like this http://user:pass@www.domain.com/va/ppp.php
It uses authentication... How can I send the username and password values?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.