Solved

How to send a header with a username & password

Posted on 2002-04-12
3
211 Views
Last Modified: 2006-11-17
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,$useragent=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-urlencoded\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?
0
Comment
Question by:matrix717
3 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 50 total points
ID: 6954782
fputs($fp, "Authorization: Basic " . base64_encode($uname . ":" . $pwd) . "\n");    
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question