[PgSQL] Membersysteem (simpel)
Auteur: Wim - 15 april 2006 - 20:09 - Gekeurd door: nemesiskoen - Hits: 22748 - Aantal punten: 4.38 (8 stemmen)
MySQL wordt -terecht- zeer veel gebruikt door webmasters. Dit omdat het praktisch op elke host aanwezig is. Maar men moet steeds in het achterhoofd houden dat er alternatieven zijn, zoals PgSQL (postgreSQL).
Het script is een uiterste basis... Met dit moet je wel in staat zijn om een groot PgSQL membersysteem te bouwen (de basis is er al ...)
PgSQL is een zeer 'relaxte' database. De installatie (linux) is ook alles behalve moeilijk! ( Klik (tutorial))
De PgSQL table:
CREATE TABLE members (
username varchar(50) NOT NULL,
password varchar(32) NOT NULL,
email varchar(150) NOT NULL,
);
Bij deze hoop ik PgSQL wat populairder zien te worden op SiMa (De crew zal dit ook leuk vinden denk ik ... :-))
|
Code: |
global.cfg.php
<?php
$pgsql['host'] = '127.0.0.1'; // host (localhost = 127.0.0.1)
$pgsql['port'] = '5432'; // poort (standaard 5432)
$pgsql['user'] = ''; // username
$pgsql['pass'] = ''; // password
$pgsql['db'] = ''; // database
?>
<?php $pgsql['host'] = '127.0.0.1'; // host (localhost = 127.0.0.1) $pgsql['port'] = '5432'; // poort (standaard 5432) $pgsql['user'] = ''; // username $pgsql['pass'] = ''; // password $pgsql['db'] = ''; // database ?>
global.inc.php
<?php
require_once ('global.cfg.php');
$connect_string = 'host='.$pgsql['host'].' port='.$pgsql['port'].' user='.$pgsql['user'].' password='.$pgsql['pass'].' dbname='.$pgsql['db'];
$pgcon = pg_connect($connect_string); // connected!
?>
<?php require_once ('global.cfg.php'); $connect_string = 'host='.$pgsql['host'].' port='.$pgsql['port'].' user='.$pgsql['user'].' password='.$pgsql['pass'].' dbname='.$pgsql['db']; $pgcon = pg_connect($connect_string); // connected! ?>
global.end.php
<?php
pg_close($pgcon);
?>
login.php
<?php
require_once ('global.inc.php');
if(isset($_POST['login'])) {
if(empty($_POST['username']) || empty($_POST['passwd']))
header('location: login.php');
$query = pg_query($pgcon, "SELECT username FROM members WHERE username='".$_POST['username']."' AND password='".md5($_POST['passwd'])."' LIMIT 1");
if(pg_num_rows($query) != 1)
die('Invalid username/password!');
setcookie('username', $_POST['username'], time()+356*24*60*60, '/');
setcookie('password', md5($_POST['passwd']), time()+356*24*60*60, '/');
echo ('You\'re now logged in!');
}
else {
echo ('<form method="post">');
echo ('Username: <input type="text" maxlenght="75" name="username" /><br />');
echo ('Password: <input type="password" name="passwd" /><br />');
echo ('<br />');
echo ('<input type="submit" name="login" value="Login" />');
echo ('</form>');
}
require_once ('global.end.php');
?>
<?php require_once ('global.inc.php'); if(isset($_POST['login'])) { if(empty($_POST['username']) || empty($_POST['passwd'])) header('location: login.php'); $query = pg_query($pgcon, "SELECT username FROM members WHERE username='".$_POST['username']."' AND password='".md5($_POST['passwd'])."' LIMIT 1"); die('Invalid username/password!'); setcookie('username', $_POST['username'], time()+356*24*60*60, '/'); echo ('You\'re now logged in !'); } else { echo ('<form method="post">'); echo ('Username: <input type="text" maxlenght="75" name="username" /><br />'); echo ('Password: <input type="password" name="passwd" /><br />'); echo ('<br />'); echo ('<input type="submit" name="login" value="Login" />'); echo ('</form>'); } ?>
register.php
<?php
require_once ('global.inc.php');
if(isset($_POST['register'])) {
if(empty($_POST['username']) || empty($_POST['email']) || empty($_POST['passwd']) || empty($_POST['passwd2']))
header('location: register.php');
if($_POST['passwd'] != $_POST['passwd2'])
die('Passwords don\'t match!');
$query = pg_query($pgcon, "SELECT username FROM members WHERE username='".$_POST['username']."'");
if(@pg_num_rows($query) > 0)
die('Username in use!');
$query = pg_query($pgcon, "SELECT username FROM members WHERE email='".$_POST['email']."'");
if(@pg_num_rows($query) > 0)
die('Email in use!');
pg_query($pgcon, "INSERT INTO members (username, password, email) VALUES ('".$_POST['username']."', '".md5($_POST['passwd'])."', '".$_POST['email']."')");
die('Account created! You can now login...');
}
else {
echo ('<form method="post">');
echo ('Username: <input type="text" name="username"><br />');
echo ('Password: <input type="password" name="passwd"><br />');
echo ('Password (again): <input type="password" name="passwd2"><br />');
echo ('E-mail: <input type="text" name="email"><br />');
echo ('<br />');
echo ('<input type="submit" name="register" value="Register">');
echo ('</form>');
}
require_once ('global.end.php');
?>
<?php require_once ('global.inc.php'); if(isset($_POST['register'])) { if(empty($_POST['username']) || empty($_POST['email']) || empty($_POST['passwd']) || empty($_POST['passwd2'])) header('location: register.php'); if($_POST['passwd'] != $_POST['passwd2']) die('Passwords don\'t match !'); $query = pg_query($pgcon, "SELECT username FROM members WHERE username='".$_POST['username']."'"); if(@pg_num_rows($query) > 0) die('Username in use!'); $query = pg_query($pgcon, "SELECT username FROM members WHERE email='".$_POST['email']."'"); if(@pg_num_rows($query) > 0) die('Email in use!'); pg_query($pgcon, "INSERT INTO members (username, password, email) VALUES ('".$_POST['username']."', '".md5($_POST['passwd'])."', '".$_POST['email']."')"); die('Account created! You can now login...'); } else { echo ('<form method="post">'); echo ('Username: <input type="text" name="username"><br />'); echo ('Password: <input type="password" name="passwd"><br />'); echo ('Password (again): <input type="password" name="passwd2"><br />'); echo ('E -mail: <input type ="text" name ="email"><br />'); echo ('<br />'); echo ('<input type="submit" name="register" value="Register">'); echo ('</form>'); } ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|