Php > Authentication
Using Postgres and PHP3 Authentication from a Web application
Using Postgres and PHP3 Authentication from a Web application Login to remove this ad. // // This little PHP script shows you how to connect to a Postgres // database via a browser with User/Password database // authentication using PHP3 authenticate function. // // 1) You have to modify the $PGDATA/pg_hba.conf file: // local all trust // -> trusting all connection for everyone on local machine // host all 127.0.0.1 255.255.255.255 password passwd // -> using password like file (passwd made using pg_passwd tool // to create user password account) to authenticate users // from everywhere // 2) Just use the pg_Connect (or pg_pConnect) function with the // connection string as follows. // In order to proceed you will need a valid username/password. exit; } // // Postgres Connection // function connect($user,$passwd) { // You simply have to change the following variables to match // your site configuration // HOSTNAME = name of your postgres base host // DBNAME = name of your postgres base $conn = pg_Connect("host=HOSTNAME dbname=DBNAME port=5432 user=$user password=$passwd"); // Db connection problem if (!$conn) { echo "Database connection error.\n"; exit; } // SQL order $query_parent="SELECT * FROM xxxx WHERE xxxx"; $result = pg_Exec($conn,$query_parent); if (!$result) { echo "SQL order problem.\n"; exit; } // ... // End of SQL statment pg_FreeResult($result); pg_Close($conn); } // // Main part of your PHP script // if (!isset($PHP_AUTH_USER)) { authenticate(); } else { connect($PHP_AUTH_USER,$PHP_AUTH_PW); } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage