RE: It's not right!
| From: | Wee Chua | Date: | Wed, 20 Sep 2000 20:24:04 +0000 |
| Subject: | RE: It's not right! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17218@lists.php.net to get a copy of this message | ||
Hi,
It's still not working after changing the hostname to "localhost" and
111.111.111.111. My situation is I have two test machines A & B. A is the
mysql server host, and B is 111.111.111.111. I have inserted a user with
username guest and host with 111.111.111.111 in user table of mysql database
on A machine. I use (grant select, insert, on MyGame.* guest@111.111.111.111
identified by "guest";) for inserting the new user. I have tried your
statement below, it still failed. Why! Thanks
$hostname=$REMOTE_ADDR; ( I also tried $hostname="localhost", none of them
worked!)
$db = @mysql_pconnect("$hostname","$username","$password") or die
("Please check you username and password to login agan");
Calvin
-----Original Message-----
From: Spencer Alewel [mailto:spencera@marathonpress.net]
Sent: Wednesday, September 20, 2000 3:28 PM
To: Wee Chua
Subject: Re: It's not right!
Hello,
If I'm understanding your problem correctly, this is what seems
to be causing you trouble:
> > $db = @mysql_pconnect("localhost", "$username", "$password")
> > or die
> ("Please check your username and password to login again.") ;
Pay special attention to the --->"localhost"<----.
Since you put "localhost" in the first argument to mysql_pconnect, every
user that tries to connect to the database is essentially trying to connect
as
$username@localhost no matter where they are actually trying to connect
from.
This will work fine for users who have "localhost" set as their allowed
hostname in the mysql user table, but will fail for users who
are only allowed to connect from say 111.111.111.111 or some other IP.
First you need to make a variable like $hostname that can be passed to
mysql_pconnect()
as the hostname, then check the $REMOTE_ADDR variable and see if it's from
the local machine. If $REMOTE_ADDR is from the local machine set $hostname
to "localhost". If $REMOTE_ADDR isn't from the local machine set $hostname
to
$REMOTE_ADDR. The call to mysql_pconnect() should then be made to look like
this:
$db = @mysql_pconnect("$hostname","$username","$password") or die
("Please check you username and password to login agan");
With $hostname being passed as the argument to mysql_pconnect,
the script will then try to connect as $username@$hostname and
not always $username@localhost.
Let me know if this helps or not.
Hope to help,
Spencer
----- Original Message -----
From: "Wee Chua" <Chua@mail.interclean.com>
To: "'Spencer Alewel'" <spencera@marathonpress.net>
Sent: Wednesday, September 20, 2000 1:46 PM
Subject: RE: It's not right!
> Hi,
> Could you tell me any errors on my statement below. If is right, why it
> failed when I have a user with a fixed ip address not localhost under host
> column in user table of mysql database. Please help! Thanks.
>
> > $db = @mysql_pconnect("localhost", "$username", "$password")
> > or die
> ("Please check your username and password to login again.") ;
> >
> > mysql_select_db("mysql", $db) or die ("Unable to connect to
> > database");
> >
> >
> > $result = mysql_query("Select host,user,password From user Where
> host='$REMOTE_USER'and user='$username' and
> password=PASSWORD('$password')",$db);
> >
> >
> > Calvin
>
> -----Original Message-----
> From: Spencer Alewel [mailto:spencera@marathonpress.net]
> Sent: Wednesday, September 20, 2000 12:38 PM
> To: Wee Chua; mysql@lists.mysql.com
> Subject: Re: It's not right!
>
>
> Hello,
>
> You could try testing $REMOTE_ADDR. If $REMOTE_ADDR is your
> own machine set some variable $hostname to "localhost" to pass to the
> hostname
> argument of mysql_pconnect(). If $REMOTE_ADDR is not from your machine
> set $hostname to $REMOTE_ADDR. Then if some legitimate user from
> 111.111.111.111
> tries to connect he/she should be able to.
>
> Hope this helps,
> Spencer
> ----- Original Message -----
> From: "Wee Chua" <Chua@mail.interclean.com>
> To: "'Spencer Alewel'" <spencera@marathonpress.net>; "MySQL
> (E-mail)"
> <mysql@lists.mysql.com>; "PHP (E-mail)" <php-general@lists.php.net>
> Sent: Wednesday, September 20, 2000 7:47 AM
> Subject: RE: It's not right!
>
>
> > Hi,
> > So how could I limit user connecting from the right hostname to match
the
> > hostname in mysql user table? Is there any ways I could do it? Thanks
for
> > your help!
> >
> > Calvin
> >
> > -----Original Message-----
> > From: Spencer Alewel [mailto:spencera@marathonpress.net]
> > Sent: Tuesday, September 19, 2000 5:52 PM
> > To: Wee Chua
> > Subject: Re: It's not right!
> >
> >
> > Hello,
> >
> > When you say there is an authentication error, do you mean the die
> statement
> > after the mysql_pconnect attempt? If you always have the host argument
in
> > the mysql_pconnect
> > set to "localhost" and you have some users who have 111.111.111.111 as
> their
> > hostname. It could
> > fail there because the hostname given as the argument doesn't match the
> > hostname in the mysql user table.
> >
> > Trying,
> > Spencer
>
>
> --
> ---------------------------------------------------------------------
> Please check "�:Z&˹ò7�f"×0�
> http://www.mysql.com/documentation/manual.php" before
> posting. To request this thread, e-mail mysql-thread51170@lists.mysql.com
>
> To unsubscribe, send a message to:
> <mysql-unsubscribe-noirotr=forges-courcelles.fr@lists.mysql.com>
>
> If you have a broken mail client that cannot send a message to
> the above address (Microsoft Outlook), you can use:
> http://lists.mysql.com/php/unsubscribe.php