Solved

How to send a header with a username & password

Posted on 2002-04-12
3
186 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
Comment Utility
fputs($fp, "Authorization: Basic " . base64_encode($uname . ":" . $pwd) . "\n");    
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now