|
|
|
//--------------------------------------------------------------
// 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.
//--------------------------------------------------------------
<?PHP
//--------------------------------------------------------------
// Authentication function - see previous archives for comments
//--------------------------------------------------------------
function authenticate() {
Header("WWW-authenticate: basic realm=\"Intranet MBDS\"");
Header("HTTP/1.0 401 Unauthorized");
$title="Login invalide";
?>
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);
}
?> |
|
| Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database. Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication | | | AUTH (.htaccess style) - a login system that uses PostgreSQL. Categories : PHP, Authentication, Databases, PostgreSQL | | | Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables | | | Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, PHP, ODBC, MySQL, PostgreSQL | | | Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate. Categories : Authentication, PHP | | | A simple class with some HTML output functions that would come in handy for consistent page layout etc. Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | Calendar using Date function Categories : HTML and PHP, PHP, Date Time, Calendar | | | phpCards - PHP/mySQL postcard script with web based admin to add, edit, and delete cards and categories. Very easy to install. Categories : PHP, Complete Programs, HTML and PHP, MySQL | | | PHP, simple, counter, bala Categories : HTML and PHP, PHP, PHP Options and Info | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions | |
|
|
|