You are here: Re: Basic Authentication problem « PHP Programming Language « IT news, forums, messages
Re: Basic Authentication problem

Posted by Jerry Stuckle on 12/12/38 11:51

fiziwig wrote:
> 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.
>


'Authorization: Basic '.base64_encode("username:password")."\r\n"

Are you putting your real username and password in here?

Also, don't know if it makes a difference - but I normally put the authorization
header just before the content type.

If you're running Firefox, you can get the Live HTTP Headers extension for it.
Print out your header and compare it to what you get when you try to access the
page with Firefox. You should be able to see what the difference is.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация