Solved

How to send a header with a username & password

Posted on 2002-04-12
3
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

624 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