Reply to Re: How to set the username/password when using http authentication?

Your name:

Reply:


Posted by Els on 03/07/07 12:40

Rik wrote:
> Els <els.aNOSPAM@tiscali.nl> wrote:
>
[using http authentication to protect one page of a cms component]
>> What I don't know though, is how I set the username and password to
>> check against, so that I can give some people permission to see that
>> form.
>>
>> Probably something really simple, but I don't see it...
>>
>> If possible, I'd like it to check against usernames that are already
>> in the database, and which have certain rights, but I'm happy already
>> if I can just set any username/password.
>
> Well, just check them against the database (mysql?):
>
> <?php
> $verified = false;
> if(isset($_SERVER['PHP_AUTH_USER'])){
> $user = mysql_real_escape_string($_SERVER['PHP_AUTH_USER']);
> $result = mysql_query("SELECT `passwd` FROM `tablename` WHERE `user` =
> '$user'");
> if(mysql_num_rows($result) == 1){
> $row = mysql_fetch_assoc($result);
> if($row['passwd']==$_SERVER['PHP_PW']) $verified = true;
> }
> }
> if(!$verfied){
> header('WWW-Authenticate: Basic realm="My Realm"');
> header('HTTP/1.0 401 Unauthorized');
> echo 'Text to send if user hits Cancel button';
> exit;
> }
> ?>

I can't seem to get that one to work.
The passwords in the database are encoded though, would that cause the
trouble?



--
Els http://locusmeus.com/

Now playing: Mr. Big - 30 Days In The Hole

[Back to original 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

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