Re: Re: Need help with HTTP-Authentication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok.
It may works with some "little" correction :

in you function CheckPwd...
You get loginname,password in your query but, you look at loginnaam and
passwod in your $sql array..
one of theses :loginname or loginnaam is not the good field :)
after this, you check if user OR password ...
It would be better to check user AND password

So, function may look like this :

function CheckPwd($user,$pass)
{
        //Open database connectie
        include("scripts/db_connect.php");
        //Maak query
        $sql_query = "SELECT DISTINCT loginnaam, password FROM
gebruikers WHERE loginnaam='$user'";
        //Verstuur query
        $sql_id = mysql_query($sql_query, $link) or die("error in
query");
        //Resultaat
        $sql = mysql_fetch_assoc($sql_id);
        $username =  $sql['loginnaam'];
        $password =  $sql['password'];

        //Sluit database connectie
        mysql_free_result($sql_id);
        mysql_close($link);
        return ($user == $username && $pass == $password) ? true :  true;
}

An other thing, you may not need to open & close your mysql connection in
the function, simply open it at the beginning of your script.
And, for testing, don't forget that you need to close all your browser
window each time ( browser keep information into memory when an
authentication is done).

Regards,
P.E.B


> You can use 2 methods :
> with a .htaccess file on your webserver, updated with your
> table fields or a direct authentification with http headers
> and a little bit of php... Tell me more? may be I could help you.

I would like to use PHP.. Well this is the code i have sofar:

<?php
function authenticate()
{
        Header( "WWW-authenticate: basic realm=\"Gastenboek admin
pagina\"");
        Header( "HTTP/1.0 401 Unauthorized");
        echo   "U moet een geldinge loginnaam en wachtwoord invoeren om
deze functie te kunnen gebruiken!\n";
        exit;
}

function CheckPwd($user,$pass)
{
        //Open database connectie
        include("scripts/db_connect.php");
        //Maak query
        $sql_query = "SELECT DISTINCT loginname, password FROM
gebruikers WHERE loginnaam='$user'";
        //Verstuur query
        $sql_id = mysql_query($sql_query, $link) or die("error in
query");
        //Resultaat
        $sql = mysql_fetch_assoc($sql_id);
        $username =  $sql['loginnaam'];
        $password =  $sql['password'];
        return ($user != $username || $pass != $password) ? false :
true;
        //Sluit database connectie
        mysql_free_result($sql_id);
        mysql_close($link);
}

if(!isset($PHP_AUTH_USER))
{
        authenticate();
}
elseif(!CheckPwd($PHP_AUTH_USER,$PHP_AUTH_PW))
{
        authenticate();
}

?>

I cannot get it to work correctly.. I have two users in my
'gebruikers'(means users) table, but i can only login with the first
user. When i try the 2nd user nothing happends. Do u know a solution or
maybe some better http-authenticate script?

Thanks alot:-)

Best regards,

Davy Obdam,
mailto:info@davyobdam.com

>
> Regards,
> P.E. Baroiller
>
> "Davy Obdam" <info@davyobdam.com> a écrit dans le message de
> news: 001901c2747e$fa0184a0$9600000a@davy...
> > Hi People,.
> >
> > I have a problem with HTTP-Authentication, i have 2 users in my
> > database, and i want both to be able to login. However it
> works, but
> > only the first user is able to login. I Use a MySQL 3.23.xx
> database,
> > PHP 4.2.3 and Apache 2.0.40. Can anyone help me with this, any help
> > would be greatly apreciated. Thanks already;-)Maybe some examples??
> > ;-)
> >
> > Best regards,
> >
> > Davy Obdam,
> > mailto:info@davyobdam.com
> >
> >
> >
> >
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux