fsockopen with http authentication problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hscbaj
Forum Newbie
Posts: 2
Joined: Wed Feb 08, 2006 11:21 am

fsockopen with http authentication problem

Post by hscbaj »

Im trying to retrieve an xml feed behind http authentication.

Using the following code, im finding that no matter what URL i specify, whether i use authentication or not, im getting a 404 every time, even when the url's exist (ive tried 3 entirely different domains).

Code: Select all

$host='www.beenhamband.org.uk';
$url='/contact.php';


$authuser='foo';      // blah ?
$authpass='bar';      // blah ?.

$authenc=base64_encode("$authuser:$authpass");

$hdr =sprintf("GET %s HTTP/1.0\r\n", $url);
$hdr .="Accept: text/html\r\nAccept: text/plain\r\n";
$hdr .="User-Agent: Mozilla/1.0 ()\r\n";
$hdr .="Authorization: Basic $authenc\r\n\r\n";

    $fp = fsockopen($host , 80, &$errno, &$errstr, 30);
    if (!$fp) {
        //die "$host open error: $errstr $errno .\n";
   }
   fputs($fp,$hdr);
   
  
    while(!feof($fp)) {
        $buff=fgets($fp,2048);
        echo $buff;  
    }
   
    fclose($fp);
Any ideas with regards to the 404 issue gratefully received.
Thanks
Baj
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tried

Code: Select all

$data = file_get_contents('http://'.$authuser.':'.$authpass.'@'.$host.$url);
:?:
hscbaj
Forum Newbie
Posts: 2
Joined: Wed Feb 08, 2006 11:21 am

Post by hscbaj »

No, but now have... and working.
File this one under "complicating the matter".

Still interested to know why i was getting 404's tho, very odd.
Post Reply