Обсуждение: Unable to connect to PostgreSQL Server: Permission denied
   
 Hi ,
 Here is the complete description of the problem ...
 I have newly installed fedora core 4 with option as everyting.
 it comes with apache webserver, postgresql , php-postgresql, php-gd etc,
 it creates a default user postgres with home = /var/lib/psql
 1. i loged in as postgres
 2. called initdb
   created database under directory ~/data
 3. changed postgresql.conf to include
       listen_addresses = '*'
       port = 5432
 4. changed pg_hba.conf
       local  all  all                        trust
       host    all  all  127.0.0.1/32        trust
       host    all  all  192.168.1.18/24      trust
       host    all  all        ::1/128        trust
 5. postmaster -i -D ~/data &
 6. createdb AddressBook
 7. psql AddressBook
 8. create table addresses( Name text, Phone text, Email text);
 9. create user www NOCREATEDB NOCREATEUSER;
 10. grant all on addresses to www;
 11. from other terminal i loged in as root
 12. changed /etc/httpd/conf/httpd.conf
     User www
     Group postgres
 13. copied add.html and add-entry.php into directory /var/www/html
 add.html
 ------------------------------------------------------
 <HTML>
 <BODY>
 <FORM ACTION="add-entry.php" METHOD="GET">
 <TABLE BORDER=1>
   <TR>
   <TD>
   <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
     <TR>
     <TD>Name</TD>
     <TD><INPUT TYPE="TEXT" NAME="Name" VALUE=""></TD>
     </TR>
     <TR>
     <TD>Phone</TD>
     <TD><INPUT TYPE="TEXT" NAME="Phone" VALUE=""></TD>
     </TR>
     <TR>
     <TD>E-mail</TD>
     <TD><INPUT TYPE="TEXT" NAME="Email" VALUE=""></TD>
     </TR>
     <TR>
     <TD COLSPAN=2 ALIGN=CENTER>
       <INPUT TYPE="SUBMIT" VALUE="Add Entry">
     </TD>
     </TR>
   </TABLE>
   </TD>
   </TR>
 </TABLE>
 </FORM>
 </BODY>
 </HTML>
 --------------------------------------------------
 add-entry.php
 --------------------------------------------------
 <HTML>
 <BODY>
 <?PHP
 $db = pg_Connect( "dbname=AddressBook user=www");
 if( !$db )
 {
   echo "Could not connect!";
   exit;
 }
 $Name=$_GET['Name'];
 $Email=$_GET['Email'];
 $Phone=$_GET['Phone'];
 $query = "INSERT INTO Addresses VALUES( '$Name', '$Phone', '$Email' );";
 $result = pg_Exec( $db, $query );
 if( !$result )
 {
   echo "No result set returned!";
   exit;
 }
 $rows = pg_NumRows( $result );
 if( $rows = 0 )
 {
   echo "Add Failed.";
   exit;
 }
 $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
 $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
 $result = pg_Exec( $db, $query );
 $row = pg_Fetch_Row( $result, 0 );
 $nameResult = $row[0];
 $phoneResult = $row[1];
 $emailResult = $row[2];
 echo "Name = $nameResult<BR>";
 echo "Phone = $phoneResult<BR>";
 echo "E-mail = $emailResult<BR>";
 pg_Close( $db );
 ?>
 <H3>Add Okay!</H3>
 </BODY>
 </HTML>
 -------------------------------------------------------------
 Error i get is
 Mon Apr 03 18:39:53 2006] [notice] Apache/2.0.54 (Fedora) configured -- resuming normal operations
 [Mon Apr 03 18:42:17 2006] [error] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico
 [client 127.0.0.1] PHP Warning:  pg_connect() [<a href='function.pg-connect'>function.pg-connect</a>]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket "/tmp/.s.PGSQL.5432"? in /var/www/html/add-entry.php on line 5, referer: http://localhost/add.html
 [Mon Apr 03 18:42:22 2006] [error] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico
 _______________________________________________________
 from the command line it works fine
 i.e php add-entry.php works fine ( ofcourse adds an empty row into the data base)
 --------------------------------------------------
 i did telnet
 [root@localhost html]# telnet localhost 5432
 Trying 127.0.0.1...
 Connected to localhost.localdomain (127.0.0.1).
 Escape character is '^]'.
 Connection closed by foreign host.
 data/pg_log/postgresql-Mon.log contains
 LOG:  invalid length of startup packet
 -------------------------------
 I am not getting any clue as to how to solve this problem ...let me know if you have any idea in solving this porblem.
 regards
 Muralidhar
			
		
On 2006-04-03 17:06:11 -0000 (Mon, Apr), muralidhar sortur wrote: > > Hi , > Here is the complete description of the problem ... > > I have newly installed fedora core 4 with option as everyting. [...] > ------------------------------------------------------------- > Error i get is > [client 127.0.0.1] PHP Warning: pg_connect(): Unable to connect to > PostgreSQL server: could not connect to server: Permission > denied\n\tIs the server running locally and accepting\n\tconnections > on Unix domain socket "/tmp/.s.PGSQL.5432"? in > /var/www/html/add-entry.php on line 5, referer: > http://localhost/add.html How does the file /tmp/.s.PGSQL.* look like? Does 'www' user have access to it? ls -l /tmp/.s.PGSQL.* As you enabled network interface in postgresql, you may try to add 'host=127.0.0.1' to your pg_connect function. This should let 'www' user to connect. > [root@localhost html]# telnet localhost 5432 > Trying 127.0.0.1... > Connected to localhost.localdomain (127.0.0.1). > Escape character is '^]'. > > > Connection closed by foreign host. > > data/pg_log/postgresql-Mon.log contains > > LOG: invalid length of startup packet Telnet is not the best tool for binary protocols. You may try netcat (nc), but anyway - this test is not significant here. By the way, you used this construction: > $Name=$_GET['Name']; > $Email=$_GET['Email']; > $Phone=$_GET['Phone']; > > $query = "INSERT INTO Addresses VALUES( '$Name', '$Phone', '$Email' );"; Forgive me if that is only because this is test, and you know that, but I just HAVE to say: Don't let the untrusted parameters to go into query. Someone may call your page like this: http://example.com/add-entry.php?Email=a'); delete from Addresses; -- As *MINIMAL* precaution use: $Name = pg_escape_string( $_GET['Name'); -- No virus found in this outgoing message. Checked by "grep -i virus $MESSAGE" Trust me.
Вложения
  Did you try to restart the PosgreSQL server using pg_ctl ?
$ pg_ctl restart
   Are you able to connect as user from the command line?
$ psql AddressBook www
  Regards,
  Javier
>
> Hi ,
> Here is the complete description of the problem ...
>
> I have newly installed fedora core 4 with option as everyting.
>
> it comes with apache webserver, postgresql , php-postgresql, php-gd etc,
>
> it creates a default user postgres with home = /var/lib/psql
>
> 1. i loged in as postgres
>
> 2. called initdb
>   created database under directory ~/data
>
> 3. changed postgresql.conf to include
>       listen_addresses = '*'
>       port = 5432
>
> 4. changed pg_hba.conf
>       local  all  all                        trust
>       host    all  all  127.0.0.1/32        trust
>       host    all  all  192.168.1.18/24      trust
>       host    all  all        ::1/128        trust
>
> 5. postmaster -i -D ~/data &
>
> 6. createdb AddressBook
>
> 7. psql AddressBook
>
> 8. create table addresses( Name text, Phone text, Email text);
>
> 9. create user www NOCREATEDB NOCREATEUSER;
>
> 10. grant all on addresses to www;
>
> 11. from other terminal i loged in as root
>
> 12. changed /etc/httpd/conf/httpd.conf
>
>     User www
>     Group postgres
>
> 13. copied add.html and add-entry.php into directory /var/www/html
>
> add.html
> ------------------------------------------------------
> <HTML>
> <BODY>
>
> <FORM ACTION="add-entry.php" METHOD="GET">
>
> <TABLE BORDER=1>
>   <TR>
>   <TD>
>   <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
>     <TR>
>     <TD>Name</TD>
>     <TD><INPUT TYPE="TEXT" NAME="Name" VALUE=""></TD>
>     </TR>
>     <TR>
>     <TD>Phone</TD>
>     <TD><INPUT TYPE="TEXT" NAME="Phone" VALUE=""></TD>
>     </TR>
>     <TR>
>     <TD>E-mail</TD>
>     <TD><INPUT TYPE="TEXT" NAME="Email" VALUE=""></TD>
>     </TR>
>     <TR>
>     <TD COLSPAN=2 ALIGN=CENTER>
>       <INPUT TYPE="SUBMIT" VALUE="Add Entry">
>     </TD>
>     </TR>
>   </TABLE>
>   </TD>
>   </TR>
> </TABLE>
> </FORM>
>
> </BODY>
> </HTML>
> --------------------------------------------------
> add-entry.php
> --------------------------------------------------
>
> <HTML>
> <BODY>
> <?PHP
> $db = pg_Connect( "dbname=AddressBook user=www");
> if( !$db )
> {
>   echo "Could not connect!";
>   exit;
> }
>
> $Name=$_GET['Name'];
> $Email=$_GET['Email'];
> $Phone=$_GET['Phone'];
>
> $query = "INSERT INTO Addresses VALUES( '$Name', '$Phone', '$Email' );";
>
> $result = pg_Exec( $db, $query );
>
> if( !$result )
> {
>   echo "No result set returned!";
>   exit;
> }
>
> $rows = pg_NumRows( $result );
>
> if( $rows = 0 )
> {
>   echo "Add Failed.";
>   exit;
> }
>
> $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
>
> $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
>
> $result = pg_Exec( $db, $query );
> $row = pg_Fetch_Row( $result, 0 );
>
> $nameResult = $row[0];
> $phoneResult = $row[1];
> $emailResult = $row[2];
>
> echo "Name = $nameResult<BR>";
> echo "Phone = $phoneResult<BR>";
> echo "E-mail = $emailResult<BR>";
>
> pg_Close( $db );
> ?>
>
> <H3>Add Okay!</H3>
>
> </BODY>
> </HTML>
> -------------------------------------------------------------
> Error i get is
> Mon Apr 03 18:39:53 2006] [notice] Apache/2.0.54 (Fedora) configured --
> resuming normal operations
> [Mon Apr 03 18:42:17 2006] [error] [client 127.0.0.1] File does not exist:
> /var/www/html/favicon.ico
> [client 127.0.0.1] PHP Warning:  pg_connect() [<a
> href='function.pg-connect'>function.pg-connect</a>]: Unable to connect to
> PostgreSQL server: could not connect to server: Permission denied\n\tIs
> the server running locally and accepting\n\tconnections on Unix domain
> socket "/tmp/.s.PGSQL.5432"? in /var/www/html/add-entry.php on
> line 5, referer: http://localhost/add.html
> [Mon Apr 03 18:42:22 2006] [error] [client 127.0.0.1] File does not exist:
> /var/www/html/favicon.ico
>
> _______________________________________________________
>
> from the command line it works fine
> i.e php add-entry.php works fine ( ofcourse adds an empty row into the
> data base)
>
> --------------------------------------------------
>
> i did telnet
>
> [root@localhost html]# telnet localhost 5432
> Trying 127.0.0.1...
> Connected to localhost.localdomain (127.0.0.1).
> Escape character is '^]'.
>
>
> Connection closed by foreign host.
>
> data/pg_log/postgresql-Mon.log contains
>
> LOG:  invalid length of startup packet
>
>
>
> -------------------------------
>
>
> I am not getting any clue as to how to solve this problem ...let me know
> if you have any idea in solving this porblem.
>
> regards
> Muralidhar
>
>
>
-------------
nediam.com.mx
			
		   
 Hi ,
 in my last mail i forgot to mention that i have restarted apache server after making changes to the httpd.conf.
 Today i made one more experiment ...
 1. changed httpd.conf 
     user apache
     Group apache
     DocumentRoot="/home/murali/html"
     <DocumentRoot "/home/murali/html">
     ......(as it is)....
     <DocumentRoot>
 2. copied the files add.html and add-entry.html to directory html under my home directory i.e 
 /home/murali/html
 3. restarted apache
 /usr/sbin/apachectl start ( from root)
 4. from postgres login started postmaster.
 postmaster -i -D data&
 5. http://localhost/add.html ( entered Name , Phone , Email)
   
 EVERY THING WORKED !!!!!
 BUT CAN ANY ONE TELL ME, WHAT WAS THE PROBLEM WITH EARLIER SETTING AND WHAT MADE IT TO WORK PROPERLY NOW !!! I NEED TO ANSWER THESE QUESTIONS
 Thanks for all of your help 
 regards
 Muralidhar
 On Tue, 04 Apr 2006 Javier Carlos wrote :
 >  Did you try to restart the PosgreSQL server using pg_ctl ?
 >
 >$ pg_ctl restart
 >
 >
 >    Are you able to connect as user from the command line?
 >
 >$ psql AddressBook www
 >
 >  Regards,
 >
 >  Javier
 >
 >
 > >
 > > Hi ,
 > > Here is the complete description of the problem ...
 > >
 > > I have newly installed fedora core 4 with option as everyting.
 > >
 > > it comes with apache webserver, postgresql , php-postgresql, php-gd etc,
 > >
 > > it creates a default user postgres with home = /var/lib/psql
 > >
 > > 1. i loged in as postgres
 > >
 > > 2. called initdb
 > >  created database under directory ~/data
 > >
 > > 3. changed postgresql.conf to include
 > >      listen_addresses = '*'
 > >      port = 5432
 > >
 > > 4. changed pg_hba.conf
 > >      local  all  all                        trust
 > >      host    all  all  127.0.0.1/32        trust
 > >      host    all  all  192.168.1.18/24      trust
 > >      host    all  all        ::1/128        trust
 > >
 > > 5. postmaster -i -D ~/data &
 > >
 > > 6. createdb AddressBook
 > >
 > > 7. psql AddressBook
 > >
 > > 8. create table addresses( Name text, Phone text, Email text);
 > >
 > > 9. create user www NOCREATEDB NOCREATEUSER;
 > >
 > > 10. grant all on addresses to www;
 > >
 > > 11. from other terminal i loged in as root
 > >
 > > 12. changed /etc/httpd/conf/httpd.conf
 > >
 > >    User www
 > >    Group postgres
 > >
 > > 13. copied add.html and add-entry.php into directory /var/www/html
 > >
 > > add.html
 > > ------------------------------------------------------
 > > <HTML>
 > > <BODY>
 > >
 > > <FORM ACTION="add-entry.php" METHOD="GET">
 > >
 > > <TABLE BORDER=1>
 > >  <TR>
 > >  <TD>
 > >  <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
 > >    <TR>
 > >    <TD>Name</TD>
 > >    <TD><INPUT TYPE="TEXT" NAME="Name" VALUE=""></TD>
 > >    </TR>
 > >    <TR>
 > >    <TD>Phone</TD>
 > >    <TD><INPUT TYPE="TEXT" NAME="Phone" VALUE=""></TD>
 > >    </TR>
 > >    <TR>
 > >    <TD>E-mail</TD>
 > >    <TD><INPUT TYPE="TEXT" NAME="Email" VALUE=""></TD>
 > >    </TR>
 > >    <TR>
 > >    <TD COLSPAN=2 ALIGN=CENTER>
 > >      <INPUT TYPE="SUBMIT" VALUE="Add Entry">
 > >    </TD>
 > >    </TR>
 > >  </TABLE>
 > >  </TD>
 > >  </TR>
 > > </TABLE>
 > > </FORM>
 > >
 > > </BODY>
 > > </HTML>
 > > --------------------------------------------------
 > > add-entry.php
 > > --------------------------------------------------
 > >
 > > <HTML>
 > > <BODY>
 > > <?PHP
 > > $db = pg_Connect( "dbname=AddressBook user=www");
 > > if( !$db )
 > > {
 > >  echo "Could not connect!";
 > >  exit;
 > > }
 > >
 > > $Name=$_GET['Name'];
 > > $Email=$_GET['Email'];
 > > $Phone=$_GET['Phone'];
 > >
 > > $query = "INSERT INTO Addresses VALUES( '$Name', '$Phone', '$Email' );";
 > >
 > > $result = pg_Exec( $db, $query );
 > >
 > > if( !$result )
 > > {
 > >  echo "No result set returned!";
 > >  exit;
 > > }
 > >
 > > $rows = pg_NumRows( $result );
 > >
 > > if( $rows = 0 )
 > > {
 > >  echo "Add Failed.";
 > >  exit;
 > > }
 > >
 > > $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
 > >
 > > $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
 > >
 > > $result = pg_Exec( $db, $query );
 > > $row = pg_Fetch_Row( $result, 0 );
 > >
 > > $nameResult = $row[0];
 > > $phoneResult = $row[1];
 > > $emailResult = $row[2];
 > >
 > > echo "Name = $nameResult<BR>";
 > > echo "Phone = $phoneResult<BR>";
 > > echo "E-mail = $emailResult<BR>";
 > >
 > > pg_Close( $db );
 > > ?>
 > >
 > > <H3>Add Okay!</H3>
 > >
 > > </BODY>
 > > </HTML>
 > > -------------------------------------------------------------
 > > Error i get is
 > > Mon Apr 03 18:39:53 2006] [notice] Apache/2.0.54 (Fedora) configured --
 > > resuming normal operations
 > > [Mon Apr 03 18:42:17 2006] [error] [client 127.0.0.1] File does not exist:
 > > /var/www/html/favicon.ico
 > > [client 127.0.0.1] PHP Warning:  pg_connect() [<a
 > > href='function.pg-connect'>function.pg-connect</a>]: Unable to connect to
 > > PostgreSQL server: could not connect to server: Permission denied\n\tIs
 > > the server running locally and accepting\n\tconnections on Unix domain
 > > socket "/tmp/.s.PGSQL.5432"? in /var/www/html/add-entry.php on
 > > line 5, referer: http://localhost/add.html
 > > [Mon Apr 03 18:42:22 2006] [error] [client 127.0.0.1] File does not exist:
 > > /var/www/html/favicon.ico
 > >
 > > _______________________________________________________
 > >
 > > from the command line it works fine
 > > i.e php add-entry.php works fine ( ofcourse adds an empty row into the
 > > data base)
 > >
 > > --------------------------------------------------
 > >
 > > i did telnet
 > >
 > > [root@localhost html]# telnet localhost 5432
 > > Trying 127.0.0.1...
 > > Connected to localhost.localdomain (127.0.0.1).
 > > Escape character is '^]'.
 > >
 > >
 > > Connection closed by foreign host.
 > >
 > > data/pg_log/postgresql-Mon.log contains
 > >
 > > LOG:  invalid length of startup packet
 > >
 > >
 > >
 > > -------------------------------
 > >
 > >
 > > I am not getting any clue as to how to solve this problem ...let me know
 > > if you have any idea in solving this porblem.
 > >
 > > regards
 > > Muralidhar
 > >
 > >
 > >
 >
 >
 >
 >-------------
 >nediam.com.mx
 >
 >
 >---------------------------(end of broadcast)---------------------------
 >TIP 5: don't forget to increase your free space map settings
			
		
Perhaps you or your host are running SE Linux??  Depending on your
configuration, users may be forced to run personal websites out of their
home directories.
Cameron
+++++++++++++++++++++++++++++++++++++
Cameron G. Moller,  Senior Officer
Technical Project Manager
SSGM Infrastructure
State Street Corporation                       ...   __o
Cell:  617-799-9049                               ...    -\<,
Desk:  617-664-4501                            ... (_)/(_) ..
+++++++++++++++++++++++++++++++++++++
             "muralidhar
             sortur"
             <sorturmuralidhar                                          To
             @rediffmail.com>          "Javier Carlos"
             Sent by:                  <nediam@nediam.com.mx>, "Gnanavel
             pgsql-php-owner@p         S" <s.gnanavel@gmail.com>,
             ostgresql.org             "pgsql_php"
                                       <pgsql-php@postgresql.org>
                                                                        cc
             04/04/2006 09:46
             AM                                                    Subject
                                       Re: [PHP] Unable to connect to
                                       PostgreSQL Server: Permission
             Please respond to         denied
                "muralidhar
                  sortur"
             <sorturmuralidhar
             @rediffmail.com>
Hi ,
in my last mail i forgot to mention that i have restarted apache server
after making changes to the httpd.conf.
Today i made one more experiment ...
1. changed httpd.conf
    user apache
    Group apache
    DocumentRoot="/home/murali/html"
    <DocumentRoot "/home/murali/html">
    ......(as it is)....
    <DocumentRoot>
2. copied the files add.html and add-entry.html to directory html under my
home directory i.e
/home/murali/html
3. restarted apache
/usr/sbin/apachectl start ( from root)
4. from postgres login started postmaster.
postmaster -i -D data&
5. http://localhost/add.html ( entered Name , Phone , Email)
EVERY THING WORKED !!!!!
BUT CAN ANY ONE TELL ME, WHAT WAS THE PROBLEM WITH EARLIER SETTING AND WHAT
MADE IT TO WORK PROPERLY NOW !!! I NEED TO ANSWER THESE QUESTIONS
Thanks for all of your help
regards
Muralidhar
On Tue, 04 Apr 2006 Javier Carlos wrote :
>  Did you try to restart the PosgreSQL server using pg_ctl ?
>
>$ pg_ctl restart
>
>
>    Are you able to connect as user from the command line?
>
>$ psql AddressBook www
>
>  Regards,
>
>  Javier
>
>
> >
> > Hi ,
> > Here is the complete description of the problem ...
> >
> > I have newly installed fedora core 4 with option as everyting.
> >
> > it comes with apache webserver, postgresql , php-postgresql, php-gd
etc,
> >
> > it creates a default user postgres with home = /var/lib/psql
> >
> > 1. i loged in as postgres
> >
> > 2. called initdb
> >  created database under directory ~/data
> >
> > 3. changed postgresql.conf to include
> >      listen_addresses = '*'
> >      port = 5432
> >
> > 4. changed pg_hba.conf
> >      local  all  all                        trust
> >      host    all  all  127.0.0.1/32        trust
> >      host    all  all  192.168.1.18/24      trust
> >      host    all  all        ::1/128        trust
> >
> > 5. postmaster -i -D ~/data &
> >
> > 6. createdb AddressBook
> >
> > 7. psql AddressBook
> >
> > 8. create table addresses( Name text, Phone text, Email text);
> >
> > 9. create user www NOCREATEDB NOCREATEUSER;
> >
> > 10. grant all on addresses to www;
> >
> > 11. from other terminal i loged in as root
> >
> > 12. changed /etc/httpd/conf/httpd.conf
> >
> >    User www
> >    Group postgres
> >
> > 13. copied add.html and add-entry.php into directory /var/www/html
> >
> > add.html
> > ------------------------------------------------------
> > <HTML>
> > <BODY>
> >
> > <FORM ACTION="add-entry.php" METHOD="GET">
> >
> > <TABLE BORDER=1>
> >  <TR>
> >  <TD>
> >  <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
> >    <TR>
> >    <TD>Name</TD>
> >    <TD><INPUT TYPE="TEXT" NAME="Name" VALUE=""></TD>
> >    </TR>
> >    <TR>
> >    <TD>Phone</TD>
> >    <TD><INPUT TYPE="TEXT" NAME="Phone" VALUE=""></TD>
> >    </TR>
> >    <TR>
> >    <TD>E-mail</TD>
> >    <TD><INPUT TYPE="TEXT" NAME="Email" VALUE=""></TD>
> >    </TR>
> >    <TR>
> >    <TD COLSPAN=2 ALIGN=CENTER>
> >      <INPUT TYPE="SUBMIT" VALUE="Add Entry">
> >    </TD>
> >    </TR>
> >  </TABLE>
> >  </TD>
> >  </TR>
> > </TABLE>
> > </FORM>
> >
> > </BODY>
> > </HTML>
> > --------------------------------------------------
> > add-entry.php
> > --------------------------------------------------
> >
> > <HTML>
> > <BODY>
> > <?PHP
> > $db = pg_Connect( "dbname=AddressBook user=www");
> > if( !$db )
> > {
> >  echo "Could not connect!";
> >  exit;
> > }
> >
> > $Name=$_GET['Name'];
> > $Email=$_GET['Email'];
> > $Phone=$_GET['Phone'];
> >
> > $query = "INSERT INTO Addresses VALUES( '$Name', '$Phone', '$Email'
);";
> >
> > $result = pg_Exec( $db, $query );
> >
> > if( !$result )
> > {
> >  echo "No result set returned!";
> >  exit;
> > }
> >
> > $rows = pg_NumRows( $result );
> >
> > if( $rows = 0 )
> > {
> >  echo "Add Failed.";
> >  exit;
> > }
> >
> > $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
> >
> > $query = "SELECT * FROM Addresses WHERE \"Name\" = '$Name';";
> >
> > $result = pg_Exec( $db, $query );
> > $row = pg_Fetch_Row( $result, 0 );
> >
> > $nameResult = $row[0];
> > $phoneResult = $row[1];
> > $emailResult = $row[2];
> >
> > echo "Name = $nameResult<BR>";
> > echo "Phone = $phoneResult<BR>";
> > echo "E-mail = $emailResult<BR>";
> >
> > pg_Close( $db );
> > ?>
> >
> > <H3>Add Okay!</H3>
> >
> > </BODY>
> > </HTML>
> > -------------------------------------------------------------
> > Error i get is
> > Mon Apr 03 18:39:53 2006] [notice] Apache/2.0.54 (Fedora) configured --
> > resuming normal operations
> > [Mon Apr 03 18:42:17 2006] [error] [client 127.0.0.1] File does not
exist:
> > /var/www/html/favicon.ico
> > [client 127.0.0.1] PHP Warning:  pg_connect() [<a
> > href='function.pg-connect'>function.pg-connect</a>]: Unable to connect
to
> > PostgreSQL server: could not connect to server: Permission denied\n\tIs
> > the server running locally and accepting\n\tconnections on Unix domain
> > socket "/tmp/.s.PGSQL.5432"? in /var/www/html/add-entry.php on
> > line 5, referer: http://localhost/add.html
> > [Mon Apr 03 18:42:22 2006] [error] [client 127.0.0.1] File does not
exist:
> > /var/www/html/favicon.ico
> >
> > _______________________________________________________
> >
> > from the command line it works fine
> > i.e php add-entry.php works fine ( ofcourse adds an empty row into the
> > data base)
> >
> > --------------------------------------------------
> >
> > i did telnet
> >
> > [root@localhost html]# telnet localhost 5432
> > Trying 127.0.0.1...
> > Connected to localhost.localdomain (127.0.0.1).
> > Escape character is '^]'.
> >
> >
> > Connection closed by foreign host.
> >
> > data/pg_log/postgresql-Mon.log contains
> >
> > LOG:  invalid length of startup packet
> >
> >
> >
> > -------------------------------
> >
> >
> > I am not getting any clue as to how to solve this problem ...let me
know
> > if you have any idea in solving this porblem.
> >
> > regards
> > Muralidhar
> >
> >
> >
>
>
>
>-------------
>nediam.com.mx
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: don't forget to increase your free space map settings
(Embedded image moved to file: pic14604.gif)
			
		Вложения
On Mon, Apr 03, 2006 at 10:01:23PM +0200, Mariusz Pękala wrote: > Telnet is not the best tool for binary protocols. > You may try netcat (nc), but anyway - this test is not significant > here. It doesn't matter here. > Don't let the untrusted parameters to go into query. Someone may call > your page like this: > http://example.com/add-entry.php?Email=a'); delete from Addresses; -- Nothing wrong will happen. Regards, -- Paweł Bernat; uselessness' lover; select'<asm'||chr(64)||'asm'||'.'||'flynet'||chr(46)||'pl>'as email; Slowly and surely the unix crept up on the Nintendo user ...
On 2006-04-04 19:35:10 +0200 (Tue, Apr), Pawel Bernat wrote: > On Mon, Apr 03, 2006 at 10:01:23PM +0200, Mariusz Pękala wrote: > > Telnet is not the best tool for binary protocols. > > You may try netcat (nc), but anyway - this test is not significant > > here. > It doesn't matter here. Okay, you're saying my English isn't perfect ? :-) > > Don't let the untrusted parameters to go into query. Someone may call > > your page like this: > > http://example.com/add-entry.php?Email=a'); delete from Addresses; -- > Nothing wrong will happen. Why? Unless I really overlooked something, I would humbly disagree. 1) It is possible to put a few sql requests in one string. 2) Relying on 'magic_quotes_gpc' and *possible* addslashes() is a bad thing, IMHO. So, where is my mistake? -- No virus found in this outgoing message. Checked by "grep -i virus $MESSAGE" Trust me.