Re: fsockopen with apache auth

From: Date: Fri, 08 Sep 2000 15:23:59 +0000
Subject: Re: fsockopen with apache auth
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-15894@lists.php.net to get a copy of this message
Hi Christian, Thanks for the update. I cut and pasted your script below into a new php file and tried it. I still have the same result (although, for some reason, I have less hair as this continues . . (:-) I can successfully access the same page(s) using either Netscape or IE with the url http://username:password@domainname.com:911/ The script is actually at the same domain as the protected directory I'm trying to reach. In other words my script is called getfile.php3 and it could be called at http://mydomain.com/getfile.php3 On a whim, I uploaded the file to another server and ran it, but with the same results. I also added a printable line number to the results to confirm that it is receiving, but rejecting, the authorization. The script is: function GetFromHost($host,$path) { $fp = fsockopen($host,911); /*don't know what happens on 911, but i guess it should work*/ set_socket_blocking($fp, true); $st= "GET $path HTTP/1.0\r\nAuthorization: Basic ".base64_encode("username:userpass")."\r\n\r\n"; fputs($fp,"$st"); while(!feof($fp)){ $x++; echo $x . nl2br(fgets($fp,1024)); } fclose($fp); } The results are : 1HTTP/1.1 401 Authorization Required 2Date: Fri, 08 Sep 2000 15:19:35 GMT 3Server: Apache/1.3.6 (Unix) AuthMySQL/2.20 4WWW-Authenticate: Basic realm="blah blah" 5Connection: close 6Content-Type: text/html 7 8 9 10 11 12 Authorization Required 13This server could not verify that you 14are authorized to access the document 15requested. Either you supplied the wrong 16credentials (e.g., bad password), or your 17browser doesn't understand how to supply 18the credentials required. I'm wondering if there is some difference between doing it with a browser and doing it via php? kind regards, bill Cristian Draghici wrote: > >Being as the Host header begins HTTP/1.1 does that mean I need > >to make a > >different type of request? Could the host be refusing a > >http1.0 "BASIC" > >request and want a different type? > > You should not use the <HOST> header when using HTTP/1.0 access. Also > servers implementing HTTP/1.1 should work just as well with HTTP/1.0 > clients. > > Does accessing the page work from IE or Netscape? > If it does, is your PHP script running on the same machine? Cause if > not, the PHP machine could be denied access to the realm in question. > (by ip or name or whatever) > > Again, this works fine for me: > > ------------ > function GetFromHost($host,$path) > { > $fp = fsockopen($host,80); /*don't know what happens on 911, but i > guess it should work*/ > set_socket_blocking($fp, true); > fputs($fp,"GET $path HTTP/1.0\r\nAuthorization: Basic > ".base64_encode("myuser:mypasswd")."\r\n\r\n"); > while(!feof($fp)){ > echo fgets($fp,1024); > } > fclose($fp); > } > > echo nl2br(GetFromHost("mywebhost", "/mydir/myscript.php")); > ------------ > > Check you setup, access rights, etc, there's nothing wrong with the > script. > cristi > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#15894) next »