| 
	
 | 
 Posted by fiziwig on 06/17/30 11:51 
Hi, 
 
I've written my first attempt at basic authentication and it doesn't 
work. I thought I understood the specs, but I must be missing something 
obvious. Can anyone give me a hint as to what might be going wrong. I 
know the username and password are correct because I can log into the 
site manually. Below is the code (with my customer's site-specific 
stuff X'ed out) : 
 
Thanks, 
--gary 
 
            $fh = fsockopen('XXXXXXXXX.com', 80, $errno, $errstr, 30); 
            if($fh) { 
                $body = 
'service=RemoveProspect&modifiers[responder]='.$group; 
                $body .= '&modifiers[email]='.$_POST['email']; 
                $body .= '&modifiers[ip]='.$ip_addr; 
                $request = 'POST /XXX/Webservice/PostServer/ 
HTTP/1.1'."\r\n" 
                          .'Authorization: Basic 
'.base64_encode("username:password")."\r\n" 
                          .'Host: XXXXXXXXX.com'."\r\n" 
                          .'Referer: 
http://'.$_SERVER['SERVER_NAME']."\r\n" 
                          ."Content-Type: 
application/x-www-form-urlencoded\r\n" 
                          .'Content-length: '.strlen($body)."\r\n" 
                          .'Connection: close'."\r\n\r\n" 
                          .$body; 
                fwrite($fh, $request); 
                $response = ''; 
                while(!feof($fh)) { 
                    $response .= fread($fh, 1024); 
                } 
                fclose($fh); 
 
The variable strings are OK because I can cut and paste them into the 
URL when I log in manually and they are accepted. But the above code 
always returns a 403, Not Authorized.
 
  
Navigation:
[Reply to this message] 
 |