Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to send a header with a username & password

Posted on 2002-04-12
3
Medium Priority
?
236 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 200 total points
ID: 6954782
fputs($fp, "Authorization: Basic " . base64_encode($uname . ":" . $pwd) . "\n");    
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

730 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